-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AwsS3V3Adapter::visibility throws Unable to retrieve the visibility for file at location UnableToRetrieveMetadata exception #1791
Comments
@terrafrost that's very weird. The visibility functions are not really intended for directories though, any particular reason why you're checking the visibility of a dir? |
I'm more specifically trying to make it so that the folders can be moved (eg. try {
$visibility = $config->get(Config::OPTION_VISIBILITY);
if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) {
$visibility = $this->visibility($source)->visibility();
}
} catch (Throwable $exception) {
throw UnableToCopyFile::fromLocationTo(
$source,
$destination,
$exception
);
} So that's where the error is ultimately coming from. I did |
Digging into it some more I see I'm getting a
The folder definitely exists on S3 (as |
@terrafrost can you try setting the global option |
Just for clarity, it's the options that you pass into the Filesystem constructor: $filesystem = new Filesystem($adapter, ['retain_visibility' => false]); |
That got me past the visibility error! Altho now it's failing here: try {
$this->client->copy(
$this->bucket,
$this->prefixer->prefixPath($source),
$this->bucket,
$this->prefixer->prefixPath($destination),
$this->visibility->visibilityToAcl($visibility ?: 'private'),
$this->createOptionsFromConfig($config)['params']
);
} catch (Throwable $exception) {
throw UnableToCopyFile::fromLocationTo($source, $destination, $exception);
} If I do
It's just weird because My current code: $client = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
],
]);
// The internal adapter
$adapter = new \League\Flysystem\AwsS3V3\AwsS3V3Adapter(
// S3Client
$client,
// Bucket name
'mybucket'
);
//$filesystem = $adapter;
$filesystem = new \League\Flysystem\Filesystem($adapter, ['retain_visibility' => false]);
//$config = new \League\Flysystem\Config();
$config = [];
//echo $filesystem->directoryExists('FakeFolder') ? 't' : 'f'; exit;
try {
$filesystem->move('RandomFolder', 'RandomFolder2', $config);
} catch (\Exception $e) {
echo $e->getMessage(); exit;
} |
So I was able to isolate this down to an issue with the S3 PHP SDK: $client = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
],
]);
$result = $client->headObject([
'Bucket' => 'mybucket',
'Key' => 'NewFolder' // an empty folder
]);
echo '<pre>';
var_dump($result); That reproduced the issue so I created an issue with AWS to get to the bottom of the issue. Here was their response:
Based on that I decided to try this instead: $result = $client->headObject([
'Bucket' => 'mybucket',
'Key' => 'NewFolder/' // an empty folder
]); And that worked! |
AwsS3V3Adapter::visibility
throwsUnable to retrieve the visibility for file at location
UnableToRetrieveMetadata exceptionHere's my code:
When I run it I get a "Unable to retrieve the visibility for file at location" UnableToRetrieveMetadata exception.
The directory does exist, per
echo $filesystem->directoryExists('RandomFolder')
- it's just that thevisibility()
method is throwing an exception.The IAM user that I'm using to connect to the S3 bucket has
AmazonS3FullAccess
andAmazonSESFullAccess
policies. The JSON for theAmazonS3FullAccess
policy is as follows:That's not exactly what https://flysystem.thephpleague.com/docs/adapter/aws-s3-v3/#iam-permissions says but it seems close enough?
Anyway, this is an issue because AwsS3V3Adapter.php's
copy()
method is calling$this->visibility()
and it's throwing an exception.Any ideas?
The text was updated successfully, but these errors were encountered: