Flutter网站无法从其他域加载网络映像 [英] Flutter web can't load network image from another domain

查看:415
本文介绍了Flutter网站无法从其他域加载网络映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过API调用从其他域中的Flutter Web中加载网络图像.收到此错误

I can't load network images in flutter web from other domains with API calls. getting this error

试图从另一个域加载图像?在以下位置找到答案: https://flutter.dev/docs/development/platform-integration/web-imagesImageCodecException:无法加载网络图像.

Trying to load an image from another domain? Find answers at: https://flutter.dev/docs/development/platform-integration/web-images ImageCodecException: Failed to load network image.

有什么帮助吗?

推荐答案

要能够在Flutter网页上显示Firebase存储中的图像,您必须为

For being able to display your images from Firebase Storage on a Flutter web page you have to configure your data for CORS.

  1. 打开 GCP控制台,选择您的项目并通过点击> _ 图标按钮.
  2. 单击打开的编辑器按钮(铅笔图标),然后创建 cors.json 文件.
  3. 运行 gsutil cors set cors.json gs://您的桶
  1. Open the GCP console, select your project and start a cloud terminal session by clicking the >_ icon button in the top navbar.
  2. Click the open editor button (pencil icon), then create the cors.json file.
  3. Run gsutil cors set cors.json gs://your-bucket

cors.json 文件应如下所示:

[
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  }
]

我将原点设置为 * ,这意味着每个网站都可以显示您的图像.但是您也可以在其中插入网站的域以限制访问.

I set the origin to * which means that every website can display your images. But you can also insert the domain of your website there to restrict the access.

如果您需要更多信息: https://cloud.google.com/storage/docs/configuring-cors

If you need more information: https://cloud.google.com/storage/docs/configuring-cors

这篇关于Flutter网站无法从其他域加载网络映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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