我有一个s3存储桶来存储我的媒体文件。它包括所有类型的数据,例如mp4,mp3 jpg和pdf。除pdf文件外,所有文件都正在加载到我的网站中。
显示错误:
Access to fetch at 'bucket_url' from origin 'my_website_url' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我的存储桶策略包括以下内容:
答案 0 :(得分:0)
您需要更改存储桶的CORS配置,以允许访问您域外的资源。您可以了解如何进行此操作here
答案 1 :(得分:0)
我尝试了以下操作: 登录控制台 铲斗已选择 权限-> CORS配置并添加了XML代码 可行!
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://example.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>https://*.example.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>