2

我收到一个无法修复的错误。我正在从 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"
});

请注意导致问题的标题范围。

这是我的 Google Storage 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 支持范围请求,但不清楚如何配置它。

4

1 回答 1

3

原来我错过了 CORS JSON 中的范围。这样一个微不足道的问题,希望谷歌提供更好的文档。

[{"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}]
于 2020-12-11T08:17:41.153 回答