从 Laravel-5.7 在 S3 中上传文件时出现错误访问拒绝 [英] Getting Error AccessDenied while upload file in S3 from Laravel-5.7
问题描述
我在上传S3 服务器上的任何文件时遇到问题.但相同的配置正在不同的项目中工作.没有改变概念,也没有改变任何配置.我正在开发 Laravel 5.8 版本.我正在共享代码和错误,请告诉我它为什么会出现?
I am facing problem while uploading any file on S3 Server. but the same configuration is working on a different project. No concept changed and no any configuration changed. I am working on Laravel 5.8 version. I am sharing code and Error please tell me why it is coming?
错误
在上执行PutObject"时出错https://coxxxxx.s3.ap-south-1.amazonaws.com/uploadFiles/pdf/2222222/2222222_COLLEGE_DETAILS_1569831261.pdf";AWS HTTP 错误:客户端错误:PUT https://colxxxxx.s3.ap-south-1.amazonaws.com/uploadFiles/pdf/2222222/2222222_COLLEGE_DETAILS_1569831261.pdf
导致 403 Forbidden
Error executing "PutObject" on "https://coxxxxx.s3.ap-south-1.amazonaws.com/uploadFiles/pdf/2222222/2222222_COLLEGE_DETAILS_1569831261.pdf"; AWS HTTP error: Client error:
PUT https://colxxxxx.s3.ap-south-1.amazonaws.com/uploadFiles/pdf/2222222/2222222_COLLEGE_DETAILS_1569831261.pdf
resulted in a403 Forbidden
AccessDenied
Access Denied3E7C4E(被截断...)AccessDenied(客户端):访问被拒绝 -
AccessDenied
Access Denied3E7C4E (truncated...)
AccessDenied (client): Access Denied -
FileSysrems.php
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL')
],
用于 S3 上的 Uplaod
$s3Path ="uploadFiles/pdf/2222222/2222222_COLLEGE_DETAILS_1569831261.pdf";
$binary_data = base64_decode($file);
$pathS3 =Storage::disk('s3')->put($s3Path, $binary_data,'public');
推荐答案
我遇到了这个问题,因为管理员在一个帐户上创建了多个存储桶.当他分成不同的帐户时,一切都开始工作.
I was facing this problem because Admin created multiple buckets on a single account. when he divided into different account then everything starts working.
另一种方法是检查您的存储桶访问权限(公共/私有).如果您的存储桶是私有的,则从代码中删除 'public'
Another way is check your Bucket access ( Public / private). if your bucket is private then remove 'public' from code
Storage::disk('s3')->put('path','file'); //code is like this.
这篇关于从 Laravel-5.7 在 S3 中上传文件时出现错误访问拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!