S3 - 访问控制允许源头 [英] S3 - Access-Control-Allow-Origin Header
问题描述
是否有人设法将 Access-Control-Allow-Origin
添加到响应标头中?我需要的是这样的:
Did anyone manage to add Access-Control-Allow-Origin
to the response headers?
What I need is something like this:
<img src="http://360assets.s3.amazonaws.com/tours/8b16734d-336c-48c7-95c4-3a93fa023a57/1_AU_COM_180212_Areitbahn_Hahnkoplift_Bergstation.tiles/l2_f_0101.jpg" />
此获取请求应包含在响应、标头中,Access-Control-Allow-Origin: *
This get request should contain in the response, header, Access-Control-Allow-Origin: *
我的存储桶 CORS 设置如下所示:
My CORS settings for the bucket looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
正如您所料,没有 Origin
响应标头.
As you might expect there is no Origin
response header.
推荐答案
通常,您需要做的就是在您的存储桶属性中添加 CORS 配置".
Usually, all you need to do is to "Add CORS Configuration" in your bucket properties.
带有一些默认值.这就是我解决您的问题所需的全部内容.只需单击保存",然后再试一次,看看它是否有效.如果没有,您也可以尝试下面的代码(来自 alxrb 的回答),它似乎对大多数人都有效.
The <CORSConfiguration>
comes with some default values. That's all I needed to solve your problem. Just click "Save" and try again to see if it worked. If it doesn't, you could also try the code below (from alxrb answer) which seems to have worked for most of the people.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
有关更多信息,您可以阅读有关编辑存储桶权限.
For further info, you can read this article on Editing Bucket Permission.
这篇关于S3 - 访问控制允许源头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!