我有一个 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 S3 阻止公有访问是一种存储桶级配置,可防止您将该存储桶中的任何对象设为公开。因此,如果您想公开一个或多个对象,例如images/*
,那么您需要为此存储桶禁用S3 阻止公共访问。
当然,这本身不会公开您的任何对象。默认情况下,S3 存储桶是私有的。要images/
公开对象,您需要配置 S3 存储桶策略,例如:
{
"Id": "id101",
"Statement": [
{
"Sid": "publicimages",
"Action": "s3:GetObject",
"Effect": "Allow",
"Resource": "arn:aws:s3:::mybucket/images/*",
"Principal": "*"
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句