rodosabbath's avatar

S3 AWS returning "Unable to check existence for: file" using Storage facade?

Hi guys. I've been facing a strange issue while using the Flysystem package for S3. Tried searching the web but little to none info about this case.

Currently using PHP 8.3.15, Laravel 11.31 and flysystem-aws-s3-v3 3.29.0

The bucket is already double checked for the right IAM permissions, as well as the config and .env file.

I can upload, delete and list all files in the bucket. However, when trying to inspect the bucket for a single file I get the following error:

League\Flysystem\UnableToRetrieveMetadata
Unable to retrieve the file_size for file at location: testimage.png.

We have another server with the same project, credentials, everything that runs without issues. It all points out to a config problem.

I also checked the file existence in the bucket.

The code, is a real simple conditional:


 if ($filename != null) {
            Log::info("Searching for: {$filename}");
            if (Storage::disk('s3')->exists($filename)) {
                Log::info("Found file");
                return Storage::disk('s3')->response($filename);
            } else {
                return $this->response->successReturn("No files were found", 200, [], true);
            }
        } else {
            $files = Storage::disk('s3')->files();
            $count = count($files);
            return $this->response->successReturn("Files:", 200, ["files" => $files, "quantity" => $count], true);
        }

I already tried using other methods like download, get, hasFile etc but it all give me a similar result.

Anyone ever faced similar issue?

0 likes
4 replies
Snapey's avatar

I would expect

Unable to retrieve the file_size for file at location: testimage.png.

to contain the full S3 resource name. Make sure you are referencing it correctly

1 like
rodosabbath's avatar

@Snapey I understand what you mean. I only pass the filename and expect the file to be returned.

What bothers me is that doing this in my other server works fine...

I noticed in my comment that I mistakenly put the error message I get when I use the Storage::disk('s3')->download("filename");

The error return from Storage::disk('s3')->exists("filename"); is below:

UnableToCheckFileExistence
Unable to check existence for: 67530e43a8403.png

Tried with other mimeTypes like mp3, xls etc.. Still the same

Snapey's avatar

@rodosabbath your s3 config contains the bucket name, and your file is stored at the root of the bucket?

rodosabbath's avatar

@Snapey I feel dumb. I identified the issue.

When I set up this new server I forgot to install some additional PHP extensions. I was missing curl, so when it tried making a stream request it failed. I inspected the strack trace with more detail and there it was easier to identify the errors returned via the AWS package.

Thanks for your assistance Snapey.

Please or to participate in this conversation.