有人设法在响应头中添加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响应头。


当前回答

@jordanstephens在评论中说过,但它有点丢失了,对我来说真的很容易修复。

我简单地添加HEAD方法并单击保存,它开始工作。

< CORSConfiguration > < CORSRule > * < AllowedOrigin > < / AllowedOrigin > < AllowedMethod > < / AllowedMethod弄> < AllowedMethod > < / AllowedMethod > <头!添加这个-> < 3000 MaxAgeSeconds > < / MaxAgeSeconds > < AllowedHeader > Authorization < / AllowedHeader > < / CORSRule > < / CORSConfiguration >

其他回答

我尝试了上面所有的答案,没有一个工作。实际上,我们需要从上述答案中总结出3个步骤来实现它:

As suggested by Flavio; add CORS configuration on your bucket: <CORSConfiguration> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> </CORSRule> </CORSConfiguration> On the image; mention crossorigin: <img href="abc.jpg" crossorigin="anonymous"> Are you using a CDN? If everything works fine connecting to origin server but NOT via CDN; it means you need some setting on your CDN like accept CORS headers. Exact setting depends on which CDN you are using.

@jordanstephens在评论中说过,但它有点丢失了,对我来说真的很容易修复。

我简单地添加HEAD方法并单击保存,它开始工作。

< CORSConfiguration > < CORSRule > * < AllowedOrigin > < / AllowedOrigin > < AllowedMethod > < / AllowedMethod弄> < AllowedMethod > < / AllowedMethod > <头!添加这个-> < 3000 MaxAgeSeconds > < / MaxAgeSeconds > < AllowedHeader > Authorization < / AllowedHeader > < / CORSRule > < / CORSConfiguration >

如果您的请求没有指定Origin头,S3将不会在响应中包含CORS头。这真的把我扔了,因为我一直试图卷曲文件来测试CORS,但卷曲不包括起源。

Set CORS configuration in Permissions settings for you S3 bucket <?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>Authorization</AllowedHeader> </CORSRule> </CORSConfiguration> S3 adds CORS headers only when http request has the Origin header. CloudFront does not forward Origin header by default You need to whitelist Origin header in Behavior settings for your CloudFront Distribution.

更新CORS配置后,请清理浏览器缓存。我的工作后清洗缓存,而与strapi工作