FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Unable to upload images to S3 #587

Closed viniciusbig closed 2 years ago

viniciusbig commented 2 years ago

Hi!

I'm trying to upload my files do an AWS S3 bucket. I've being looking online for any exemple that works with Cake4 (4.3.10) and cakephp-upload (6.0.0).

This might be an issue with the Flysystem or maybe with the integration Plugin/FlySystem. Maybe something else.

Following Jose's blog post,I can upload a file to my local file system. But when I add the adapter property I'm got an error:

Unable to write file at location: webroot/files/VehicleImages/image/banner.png.temp.

I understood that I don't need a custom ASWWriter class to do that, the DefaultWriter can handle a new FlySystem Adapter with the property adapter.

Do you have a working example or any ideia that can help me debugging this issue?

viniciusbig commented 2 years ago

So, to provide an answer:

The error message doesn't reflect the reality:

the snippet on vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php is:

try {
    $this->client->upload($this->bucket, $key, $body, $acl, ['params' => $options]);
} catch (Throwable $exception) {
    throw UnableToWriteFile::atLocation($path, '', $exception);
}

but the exception its not related to WriteFile localy, in my case it was a 403 Unauthrized error.

So, I had an Autorization issue and its not related to "Unable to Write".

This seems a bug in FlySystem adapter. Nothing to do with this plugin.

I managed to upload my file there after playing around with permissions on AWS.