Please excuse me, as there are already many questions on the same topic.
First some background: I started working on a Laravel 9 web application few months ago, created AWS S3 buckets and an IAM user with full access to AmazonS3, and used the user's access credentials in.env file. And I was able to upload files to the specified bucket, and was able to access the uploaded files in my web application.
Last week, I worked on SMTP setup for sending emails and made some changes to the.env file (though I am sure that I did not change the AWS settings). Now I notice that the uploading files to the AWS S3 bucket is failing with the message:
exception: "League\\Flysystem\\UnableToWriteFile"
file:"/var/www/vhosts/silkweb.ca/vendor/league/flysystem/src/UnableToWriteFile.php"
line: 24
message: "Unable to write file at location: user/profile/3/P2jFdBHTE49mxym6jxa4LHTAPvV0qDiFZ9SsYtZt.png. Error executing \"PutObject\"
I use the following commands to put the file in the AWS S3 bucket:
$filepath = "/user/profile/".$user_id;
$upload_path = Storage::disk('s3')->put($filepath, $request->file('file'));
I even created a new IAM user and used that user's credentials in my.env file, but still no luck. My current.env settings for AWS are as follows
AWS_ACCESS_KEY_ID=AKI***************DAY
AWS_SECRET_ACCESS_KEY=jotz*************************ru
AWS_DEFAULT_REGION=us-east-2
AWS_BUCKET=silkweb
AWS_URL=silkweb.s3.us-east-2.amazonaws.com
AWS_ENDPOINT=http://silkweb-s3.us-east-2.amazonaws.com
AWS_USE_PATH_STYLE_ENDPOINT=false
I have used php artisan clear:cache and php artisan config:clear several times.
Any idea, why I am not able to create a file in the AWS S3 bucket?
After I commented the AWS_URL and AWS_ENDPOINT, file upload started working. The following are the working settings
AWS_ACCESS_KEY_ID=AKI***********DG
AWS_SECRET_ACCESS_KEY=l36***************0C
AWS_DEFAULT_REGION=us-east-2
AWS_BUCKET=silkweb
AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_S3_SILKWEB_URL="https://silkweb.s3.us-east-2.amazonaws.com/"
**#AWS_URL=silkweb.s3.us-east-2.amazonaws.com**
**#AWS_ENDPOINT=http://silkweb-s3.us-east-2.amazonaws.com**
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.