火力存储上的 CORS [英] CORS on firebase storage

查看:18
本文介绍了火力存储上的 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我对 html 文件进行 get 调用时,我的 firebase 存储出现了正常的 cors 错误:

I'm gettin the normal cors error on my firebase storage when I do a get call on an html file:

Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

我正在使用 axios 进行调用:

I'm using axios for the call:

axios.get('https://firebasestorage.googleapis.com/v0/b/xxxxx-xxxxx.appspot.com/o/files%2Fsigning%2F148%2F459.html?alt=media&token=f3be2ef2-a598-4c30-a77b-8077e8b1f7bc',
{
   headers: {'Access-Control-Allow-Origin': '*',}
)

我已将访问权限设置为公开:

I have the access set to public:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

当我加载图像时,同样的设置工作正常,但它给了我存储的 html 文件的错误.关于如何解决它的任何想法?

This same setup works fine when I load images but it's giving me the error for the stored html file. Any thoughts on how to fix it?

推荐答案

Firebase 使用与 google cloud 相同的存储基础架构,即使没有 firebase 方法来设置 cors 规则,您也可以使用 gc setup.首先你需要安装google cloud sdk:

Firebase is using the same storage infrastructure as google cloud and even though there is no firebase method to set the cors rules, you can use gc set up. First you need to install google cloud sdk:

curl https://sdk.cloud.google.com | bash

重启你的shell:

exec -l $SHELL

初始化 gcloud.这将要求您选择您的帐户并进行身份验证.

Initialize gcloud. This will ask you to select your account and authenticate.

gcloud init

然后创建一个json文件,内容如下

Then create a json file with the following content

[
    {
      "origin": ["http://example.appspot.com"],
      "responseHeader": ["Content-Type"],
      "method": ["GET", "HEAD", "DELETE"],
      "maxAgeSeconds": 3600
    }
]

然后用你的 firebase storage gc:endpoint 运行它

And run this with your firebase storage gc: endpoint

gsutil cors set yourFile.json gs://yourProject

这也应该可以为您解决问题.

That should fixe the problem for you as well.

这篇关于火力存储上的 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆