Flutter web 无法从另一个域加载网络图像 [英] Flutter web can't load network image from another domain
问题描述
我无法通过 API 调用从其他域加载 flutter web 中的网络图像.收到这个错误
<块引用>试图从另一个域加载图像?在以下位置找到答案:https://flutter.dev/docs/development/platform-integration/web-imagesImageCodecException: 无法加载网络图像.
有什么帮助吗?
为了能够在 Flutter 网页上显示来自任何其他域或 Firebase Storage 的图像,您必须为 CORS.
打开 GCP 控制台,选择您的项目并通过点击启动云终端会话顶部导航栏中的
>_
图标按钮.单击打开编辑器按钮(铅笔图标),然后创建
cors.json
文件.
cors.json
文件应如下所示:
我将原点设置为 *
这意味着每个网站都可以显示您的图像.但是您也可以在那里插入您网站的域来限制访问.
- 运行
gsutil cors set cors.json gs://your-bucket
如果您需要更多信息:https://cloud.google.com/storage/文档/配置-cors
I can't load network images in flutter web from other domains with API calls. getting this error
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.
any help?
For being able to display your images from any other Domain or from Firebase Storage on a Flutter web page you have to configure your data for CORS.
Open the GCP console, select your project and start a cloud terminal session by clicking the
>_
icon button in the top navbar.Click the open editor button (pencil icon), then create the
cors.json
file.
The cors.json
file should look like this:
[
{
"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 access.
- Run
gsutil cors set cors.json gs://your-bucket
If you need more information: https://cloud.google.com/storage/docs/configuring-cors
这篇关于Flutter web 无法从另一个域加载网络图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!