skip to Main Content

I have installed the package with composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies to my laravel and config the .env file. But I am unable to upload file to s3:

    $filename = "Picture3.png";
    $file = Storage::disk("public")->get($filename);
    $status = Storage::disk("s3")->put("post_thumbnails/".$filename, $file);
    dd($status);

When I try to run it, the dd() return with false. How can I get more info instead of just false to find out what causes file fail to upload?

2

Answers


  1. You can add 'throw' => true to your config/filesystems.php file. This will throw exceptions instead of just returning false.

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => 'us-east-1',
        'bucket' => 'abcd',
        'throw' => true, // Failures will throw exceptions
    ],
    
    Login or Signup to reply.
  2. If I were in your situation (e.g. not getting any helpful error messages), I would inspect the underlying code.

    If you go to the IlluminateFilesystemFilesystemAdapter class and look at the implementation of the put() method, then you will find that at line 374 this method returns false if either a LeagueFlysystemUnableToWriteFile or a LeagueFlysystemUnableToSetVisibility exception was thrown. This means that you need to check for the visibility of the directories inside your bucket (as stated in https://flysystem.thephpleague.com/docs/adapter/aws-s3-v3/) and ensure that they’re public, or that you have to set writing permissions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search