firebase - 使用 Firebase 托管的 Flutter Web 无法从存储加载图片

标签 firebase flutter firebase-hosting flutter-web

我正在开发一个 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 进行设置后,现在可以正常工作了!

https://stackoverflow.com/a/58613527/11231634

关于firebase - 使用 Firebase 托管的 Flutter Web 无法从存储加载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63459488/

相关文章:

javascript - Firebase 身份验证无法使用 Vue 和 Vuex

ios - 使用新的 Firebase 在 Heroku 上为 ElasticSearch 设置手电筒

android - 如何从 Firebase 获取时间戳?安卓

firebase - Flutter是否支持Firebase动态链接?

reactjs - 将服务器端渲染添加到 Firebase 上托管的现有 React+Redux+React-Router 应用程序

ios - Flutter - 在 IOS 上使用 FCM 进行后台通知

asynchronous - 在特定时间等待 future

flutter - 如何在 Flutter 中使用第三方包计算代码(Dio 和 path_provider)

Firebase 托管 Webhook

debugging - 是否可以像我们在节点中那样使用 --inspect-brk 启动 firebase 服务?