Firebase存储上的CORS [英] CORS on firebase storage
问题描述
当我对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设置。
首先,您需要安装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存储gc运行此程序:端点
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.
这篇关于Firebase存储上的CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!