[英]AWS S3 bucket , uploaded image files are accessible only after setting individual object permission to public manually
I have created a bucket & after image uploaded from my website development server it store as XML file, If I go to bucket and make it public manually it becomes available to all and I am able to get that file.我已经创建了一个存储桶,并且在从我的网站开发服务器上传图像后,它将存储为 XML 文件,如果我将 go 存储到存储桶中并手动将其公开,则它可供所有人使用,并且我可以获取该文件。
What might be the problem here?这里可能有什么问题?
setting each uploaded file to public as below将每个上传的文件设置为公开,如下所示
I set access= objects can be public
我设置
access= objects can be public
Block all public access = False
CORS CONFIGURATION CORS 配置
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<ExposeHeader>ETag</ExposeHeader>
<ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
INITIAL ERROR WHEN TRYING TO ACCESS THE UPLOADED IMAGE尝试访问上传的图像时出现初始错误
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>InvalidRequest</Code>
<Message>The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.</Message>
<RequestId>XX</RequestId>
<HostId>XXZjXX</HostId>
</Error>
The setting itself is to allow them the ability to be public.设置本身就是允许他们公开的能力。
If you want all objects (or those with a specific prefix) then take a look at create a S3 bucket policy that allows the S3:GetObject
permission.如果您想要所有对象(或具有特定前缀的对象),请查看创建允许
S3:GetObject
权限的 S3 存储桶策略。
An example of this bucket policy is available here . 此处提供了此存储桶策略的示例。
If I go to bucket and make it public manually it becomes available to all and I am able to get that file.
如果我将 go 存储到桶中并手动将其公开,则所有人都可以使用它,并且我可以获取该文件。 What might be the problem here?
这里可能有什么问题?
You don't have to do it manually.您不必手动操作。 Instead, to automatically make all objects in your bucket publicly readable, a bucket policy can be added:
相反,要自动使存储桶中的所有对象公开可读,可以添加存储桶策略:
For example:例如:
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicRead",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::<your-bucket-name>/*"]
}
]
}
You will also need to keep block public access settings
disabled.您还需要禁用阻止
block public access settings
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.