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
You can add
'throw' => true
to yourconfig/filesystems.php
file. This will throw exceptions instead of just returning false.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 theput()
method, then you will find that at line 374 this method returnsfalse
if either aLeagueFlysystemUnableToWriteFile
or aLeagueFlysystemUnableToSetVisibility
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.