League\Flysystem\UnableToRetrieveMetadata Unable to retrieve the visibility for file at location:
Hey all, hoping someone can help.
Filament Version: 3.2
Laravel: 10.43
league/flysystem-aws-s3-v3": "^3.0"
I am getting the following error when trying to upload files to S3 through the RichEditor. S3 uploads work fine with a simple FileUpload field, and also using Laravel Media Library file upload field, but during upload inside an editor I am getting this error:
League\Flysystem\UnableToRetrieveMetadata Unable to retrieve the visibility for file at location:
My code:
I tracked the error to line 120 of the HasFileAttachments trait which is inside a method name handleUploadedAttachmentUrlRetrieval()
.
Line 120: if ($storage->getVisibility($file) === 'private') {
The getVisibility method is throwing the error. However, the file is successfully uploaded to S3 and $file is pointed at the correct location: example: attachments/QB4Gc4ioPAaBnvPkYIeGVjqBT7LQakY0qAqVL1cB.jpg
When commenting out the if statement on line 120 to test, the image does render in the editor but I have no idea why it can't read the visibility.
Any help appreciated!
Thanks
Ralph8 Replies
I’m pretty sure that using s3 requires setting the visibility to private. Even if it sounds backwards and unnecessary.
But that could introduce issues since the RichEditor image tag will have a token that will expire.
Thanks very much for your reply. Unfortunately I've tried setting the visibility to private as a test and the file is uploaded as private, correctly, but I still get the same error of
Unable to retrieve the visibility for file at location
.
And yes, I think the file would have to be public otherwise the token will expire as you say.Any console errors?
Basically though it’s saying it can’t read the file from s3 for whatever reason.
Is this a Spatie media library integration or just native Filament uploads?
Just native file upload.
No console errors
Yeah, it can't read the visibility with
($storage->getVisibility($file)
. But it can render the file with $storage->url($file)
.Hmm. Sorry not sure.
Wish I had a solid answer for you.
No worries. I appreciate the help. And I just figured it out!
I went down the rabbit hole going deeper into flysystem and found the root of the error message. I needed to add s3:GetObjectAcl to my IAM policy in AWS.
Ugh. That’s why I hate Aws. Lol. Glad you figured it out though.
Makes sense, but so difficult to work with sometimes.
Thanks. Feeling relieved as I've been banging my head and searching google/github issues for hours and it's 1.20am here. So going to bed! Nice to have that fixed.
Cheers again