【发布时间】:2021-05-08 12:19:24
【问题描述】:
我将以下 s3 配置添加到我的 AWS S3 存储桶 cors 设置中。
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"https://*.herokuapp.com"
],
"ExposeHeaders": []
},
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
现在当我尝试使用下面的 JS 读取它时,我遇到了错误。
async function covertToBlob(url) {
// https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
const resp = await fetch(url, {
credentials: 'include',
});
const blobVal = await resp.blob();
return blobVal;
}
错误是:
访问获取 'https://dhdhddh.s3.amazonaws.com/docs/attachment/6f56abfe-a355-44b9-b728-a642f661a8e7/file/3ed4e889-e139-4755-81e9-5383310e07e7/remote_sounding_system_Hanla.pdf' 来自原产地“http://localhost:3000”已被 CORS 政策阻止: 响应中“Access-Control-Allow-Origin”标头的值 当请求的凭证模式为 '包括'。
你能给我一些关于如何解决这个问题的想法吗?
【问题讨论】:
标签: javascript amazon-s3 cors fetch