我有一个 S3 存储桶eu-west-1
地区,我们称之为my-bucket
.
那个桶里有一张照片,我们就叫它吧some-file.jpg
.
如果我通过浏览器访问这两个网址,我可以检索该图片(存储桶中的所有对象都是公共的)(请记住,这些是示例,而不是现实生活中的网址):
https://my-bucket.s3.amazonaws.com/some-file.jpg https://my-bucket.s3.amazonaws.com/some-file.jpg
https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg
但是,我正在尝试获取有关该图片的一些信息,为此我正在使用 Vivitel.js,它会尝试检索该文件。
但是,当 url 为:https://my-bucket.s3.amazonaws.com/some-file.jpg https://my-bucket.s3.amazonaws.com/some-file.jpg,出现以下 CORS 错误:
Access to Image at 'https://my-bucket.s3.amazonaws.com/some-file.jpg' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://example.com' is therefore not allowed access
我已确保存储桶的 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>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我的猜测是https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg发送Access-Control-Allow-Origin
而另一个则没有。我该如何解决这个问题?