You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Storage跨域请求遭CORS策略拦截问题求助

Firebase Storage图片加载遇CORS拦截问题

加载图片的代码:

const blob = await fetch(
    "https://firebasestorage.googleapis.com/...?alt=media"
  )
  .then((r) => r.blob())
  
const reader = new FileReader();

reader.onload = function() {
  const objectUrl = reader.result as string;
  // 处理object url
};

reader.readAsDataURL(blob);

浏览器报错信息:

Access to image at 'https://firebasestorage.googleapis.com/...?alt=media' from origin 'http://localhost:5000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

直接在浏览器地址栏输入图片URL可正常加载,确认资源存在且路径正确。

已执行的操作:

  • 创建CORS配置文件cors.json:
[
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  }
]
  • 通过GCP Cloud Shell执行命令更新存储桶CORS配置:
$ gsutil cors set cors.json gs://my-bucket-name
  • 查询配置确认已生效:
$ gsutil cors get gs://my-bucket-name
[{"maxAgeSeconds": 3600, "method": ["GET"], "origin": ["*"]}]
  • 尝试在配置中添加"OPTIONS"方法,问题依旧存在。

请求网络详情截图:

请求网络详情截图

求调试方向或解决方案建议。

内容的提问来源于stack exchange,提问作者vighnesh153

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:13:19