Skip to content
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

S3 exists method fails on non existent file #50062

Closed
emmettculley opened this issue Feb 12, 2024 · 3 comments
Closed

S3 exists method fails on non existent file #50062

emmettculley opened this issue Feb 12, 2024 · 3 comments

Comments

@emmettculley
Copy link

Laravel Version

10.43.0

PHP Version

8.1.27

Database Driver & Version

PostgreSql 10

Description

On S3, using Storage::exists($file_path) on a file that does not exist causes a whoops with the following error:

"UnableToCheckFileExistence"

If the file does exist, it returns true, and I am able to complete the action (delete, append, get).

"league/flysystem-aws-s3-v3": "^3.24.0",

I found a similar issue in issue #45639 (closed). From that I've verified that the bucket does have the s3:ListBucket permission mentioned in that issue.

I first tried it first with "league/flysystem-aws-s3-v3": "^3.11.0", and that didn't work either.

Steps To Reproduce

InvalidArgumentException UnableToCheckFileExistence
HTTP 500 Internal Server Error
Unable to check existence for:
League\Flysystem
UnableToCheckFileExistence

        if (!is_null($this->file_pdf)) {
            if (Storage::exists($this->file_pdf)) {
                Storage::delete($this->file_pdf);
            }
        }

FILESYSTEM_DISK=s3

@emmettculley
Copy link
Author

Resolved. Turns out negelected to add 'use Storage' at the top. As soon as I added that line all was well.

I am surprised leavin that out didn't cause an exception on page load.

@emmettculley
Copy link
Author

I was wrong. I was testng on wrong instance. The use Illuminate\Support\Facades\Storage; line was already in the file and an exception did happen when I attempted to run that controller method.

I am still at a loss, as the Storage::exists($filename) construct is used successfully in other methods. I'll need to verify that I am testing on those other methods that the file is missing.

@emmettculley
Copy link
Author

Not at a loss now. Found that the variable containing the path was empty and I was testing for null, so I was calling Storate::exists($file) with an empty variable.

So now we know that calling Storage::exists with an empty string produced the "UnableToCheckFileExistence" error. Woluld have been nice if the error message was more informative.

Mayber this convoluted bug report will help somebody someday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant