簡體   English   中英

Flutter web 與 Firebase 主機無法從存儲中加載圖片

[英]Flutter web with Firebase Hosting can not load pictures from storage

我正在開發一個 flutter web 應用程序,當我在調試模式(本地主機)上運行它時,它就像一個魅力,我的 Firestore 請求和存儲 URL 也可以工作,但是當我將它部署到 Z035489FF8D092741943E4A8324圖片使用 url 從存儲。 這就是我得到的:

從源“https://my-project.web.app”訪問“https://firebasestorage.googleapis.com/v0/b/url-to-my-picture/?token=firestorage-key”已被 CORS 策略阻止:請求的資源上不存在“Access-Control-Allow-Origin”header。 如果不透明的響應滿足您的需求,請將請求的模式設置為“no-cors”以獲取禁用 CORS 的資源。

我搜索了這個,我發現我需要在 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,
),
...

通過谷歌 shell 進行設置后,它現在可以工作了!

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM