我收到一个错误,但无法找到修复方法。我正在从 Google Cloud Storage 发送 CORS 资源的获取,但是当我发送但不包含范围请求时,它会起作用。但如果我添加范围请求,它就会失败。可能会出现什么问题?
fetch("https://storage.googleapis.com/bucket/abc.pdf", {
"headers": {
"range": "bytes=24772608-24832146"
},
"referrer": "http://localhost:8000/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "omit"
});
请注意导致问题的 header 范围。
这是我的 Google 存储 CORS 配置:
[{"origin": ["*"],"responseHeader": ["Content-Type", "Accept-Ranges", "Content-Range", "Content-Encoding", "Content-Length","Access-Control-Allow-Origin"],"method": ["GET", "HEAD", "OPTIONS"],"maxAgeSeconds": 3600}]
Google Cloud Storage 支持范围请求,但不清楚如何配置它。
最佳答案
原来我缺少 CORS JSON 中的范围。这么简单的问题,希望 Google 能给出更好的文档。
[{"origin": ["*"],"responseHeader": ["Content-Type", "Accept-Ranges", "Content-Range", "Content-Encoding", "Content-Length","Access-Control-Allow-Origin","Access-Control-Allow-Methods","Range"],"method": ["GET", "HEAD", "OPTIONS"],"maxAgeSeconds": 3600}]
关于google-chrome - 使用 Google Cloud Storage 的 Google Chrome 中的范围请求出现 CORS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65246709/