使用 fetch 在启用通配符 CORS 的 gcs 存储桶上遇到 CORS 问题

Gar*_*t S 3 fetch cors google-cloud-storage

我在 Google Cloud Storage 中存储了一个公开可用的文件,并且在使用 fetch 从 SPA 检索资源时遇到问题。假设存储桶名称为pub-bucket,完整资源 URL 为https://storage.googleapis.com/pub-bucket/v1/example.mid。我已使用存储桶的以下 JSON 配置启用了 CORS

[
    {
      "origin": ["*"],
      "method": ["GET"]
    }
]
Run Code Online (Sandbox Code Playgroud)

但我仍然收到相同的 CORS 错误,Access to fetch at 'https://storage.googleapis.com/pub-bucket/v1/example.mid' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.我不确定是否有某些配置错误,就像之前我使用具有相同 CORS 配置的 DO Spaces 一样,但从未见过此问题。我还尝试使用答案中提到的更多选项来扩展我的 CORS 配置,但没有任何改变。

Gar*_*t S 7

事实证明,这个问题是由于 Google 没有明确定义可以使用 CORS 访问哪些端点。此资源的 URI 版本https://storage.googleapis.com/[YOUR-BUCKET]/[OBJECT-PATH]不允许CORS 访问,但允许https://[YOUR-BUCKET].storage.googleapis.com/[OBJECT-PATH]