【发布时间】:2020-01-24 22:21:53
【问题描述】:
我有一个 s3 存储桶(例如 mybucket),目前其权限设置如下:
Block all public access
On
|
|_Block public access to buckets and objects granted through new access control lists (ACLs)
| On
|
|_Block public access to buckets and objects granted through any access control lists (ACLs)
| On
|
|_Block public access to buckets and objects granted through new public bucket or access point policies
| On
|
|_Block public and cross-account access to buckets and objects through any public bucket or access point policies
On
在这个桶里面我有两个文件夹:
images (e.g. https://mybucket.s3.us-west-2.amazonaws.com/images/puppy.jpg)
private (e.g. https://mybucket.s3.us-west-2.amazonaws.com/private/mydoc.doc)
我希望图像文件夹可以公开访问,以便我可以在我的网站上显示图像
我希望私有文件夹受到限制,并且只能使用 IAM 帐户以编程方式访问
如何设置这些权限?我试过关闭上述权限,我也点击了图片 并在操作下,点击“公开”。然后我尝试上传以下内容:
$image = Image::make($file->getRealPath())->resize(360, 180);
Storage::disk('s3')->put($filePath, $image->stream());
文件已上传,但当我尝试按如下方式显示图像时出现 403 错误:
<img src="{{ Storage::disk('s3')->url($file->path) }}" />
要下载私人文件,我有以下内容:
$response = [
'Content-Type' => $file->mime_type,
'Content-Length' => $file->size,
'Content-Description' => 'File Transfer',
'Content-Disposition' => "attachment; filename={$file->name}",
'Content-Transfer-Encoding' => 'binary',
];
return Response::make(Storage::disk('s3')->get($file->path), 200, $response);
设置这些权限的正确方法是什么?
在任何人开始大喊我是 S3 存储新手之前,请耐心等待。
任何帮助和指导将不胜感激。
【问题讨论】:
标签: amazon-web-services amazon-s3 permissions laravel-6