我正在开发一个 flutter Web 应用程序,当我在 Debug模式(本地主机)上运行它时,它就像一个魅力,我的 firestore 请求也可以工作,存储 URL 也可以,但是当我将其部署到 Firebase 托管时,我可以不使用存储中的 url 加载图片。这是我得到的:
Access to fetch at 'https://firebasestorage.googleapis.com/v0/b/url-to-my-picture/?token=firestorage-key' from origin 'https://my-project.web.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我搜索了这个,我发现我需要在 firebase.json 文件上设置我的托管,这就是我在托管部分所做的:
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"headers": [
{
"source": "**",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
}
]
},
但是没有成功。请注意,我仅使用 Flutter Web 和 Firebase 本身。没有 NodeJ,没有 php。
编辑: 这是我加载图片的方式:
...
NetworkImage(
pic.url,
),
...
最佳答案
通过 google shell 进行设置后,现在可以正常工作了!
关于firebase - 使用 Firebase 托管的 Flutter Web 无法从存储加载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63459488/