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
相关产品推荐
相关产品推荐

