有人设法在响应头中添加Access-Control-Allow-Origin吗?
我需要的是这样的东西:
<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" />
这个get请求应该在响应中包含Access-Control-Allow-Origin: *
我的CORS设置桶看起来像这样:
<?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响应头。
我最近遇到了同样的问题,似乎AWS对我们定义CORS配置的方式做了一些更改。例如,如果你想允许某些方法在过去的S3桶上,你必须在编辑器上做这样的事情:
下面的配置与上面的配置相同,但采用数组的形式。
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"HEAD",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
这是一种简单的工作方法。
我知道这是一个老问题,但仍然很难找到解决办法。
首先,我用Rails 4、Paperclip 4、CamanJS、Heroku和AWS S3构建了一个项目。
你必须使用crossorigin: "anonymous"参数请求你的图像。
<img href="your-remote-image.jpg" crossorigin="anonymous">
Add your site URL to CORS in AWS S3. Here is a refference from Amazon about that. Pretty much, just go to your bucket, and then select "Properties" from the tabs on the right, open "Permissions tab and then, click on "Edit CORS Configuration".
Originally, I had < AllowedOrigin> set to *. Just change that asterisk to your URL, be sure to include options like http:// and https:// in separate lines. I was expecting that the asterisk accepts "All", but apparently we have to be more specific than that.
对我来说是这样的。