Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS errors on Flutter web #972

Open
1 of 3 tasks
Kurczaak opened this issue Sep 19, 2024 · 11 comments
Open
1 of 3 tasks

CORS errors on Flutter web #972

Kurczaak opened this issue Sep 19, 2024 · 11 comments

Comments

@Kurczaak
Copy link

🐛 Bug Report

This bug happened to me after a while of using the package so it might not be easy to reproduce.
I am unable to run my project due to CORS policies. This does not happen using Flutter's Image.network. I am fetching data from my Contentful CMS backend.

Expected behavior

Flutter web project run flawlesly

Reproduction steps

Run a Flutter Web app and try to load images from Contentful CMS backend.

Configuration

Version: 3.4.1

Platform:

  • 📱 iOS
  • 🤖 Android
  • 🕸️ Web
@Remy2701
Copy link

You can change the imageRenderMethodForWeb parameter to ImageRenderMethodForWeb.HttpGet instead of ImageRenderMethodForWeb.HtmlImage and that should fix your issue.

@pauljonescodes
Copy link

I'm still debugging this issue for my app so I'm not 100% sure on the specifics, but for what it's worth that fix did not work for me, and it appears the enum is a package other than this one I directly depend on.

@Kurczaak
Copy link
Author

I'm currently not able to check it, but I recall I tried to go for other method but couldn't use the enum

@pauljonescodes
Copy link

I solved my problem by using the HTML renderer, it appears the default may have changed in some Flutter version upgrade. It would also appear like this is deprecated by Flutter, so I'm not sure I'd advise this solution for others if it can be avoided. Further, I'm accessing an S3 bucket which I do not control, I believe I could solve this is I controlled the CORS configuration and allowed all hosts.

@rayliverified
Copy link

Even with allow all hosts, images fail to load.

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

I wonder if it's because Wasm requires stricter headers. For example, deploying Wasm requires the server to serve these headers.

    {
      "source": "/(.*)",
      "headers": [
        {
          "key": "Cross-Origin-Embedder-Policy",
          "value": "credentialless"
        },
        {
          "key": "Cross-Origin-Opener-Policy",
          "value": "same-origin"
        }
      ]
    }

Wasm might require all files to be returned with

"responseHeader": ["Content-Type"],

@max-anders
Copy link

I encountered the following error:
ImageCodecException: Failed to load network image.

Adding this helped resolve the issue:
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,

However, I am still facing another issue,
GET https://lh3.googleusercontent.com/a/ACg8ocJEb--2bAckEYPPmMs8PL_tR031rtQ5pXJQF6ZNQWPQZBNnUw=s96-c 429 (Too Many Requests)

this is my cors

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

The images load fine on mobile, but I am encountering a 429 (Too Many Requests) error on the web.

@luca1994ioma
Copy link

I encountered the following error: ImageCodecException: Failed to load network image.

Adding this helped resolve the issue: imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,

However, I am still facing another issue, GET https://lh3.googleusercontent.com/a/ACg8ocJEb--2bAckEYPPmMs8PL_tR031rtQ5pXJQF6ZNQWPQZBNnUw=s96-c 429 (Too Many Requests)

this is my cors

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

The images load fine on mobile, but I am encountering a 429 (Too Many Requests) error on the web.

I have the same problem. Have you found a solution?

@Remy2701
Copy link

Remy2701 commented Oct 9, 2024

For me changing the method worked. I did have to add the cached_network_image_platform_interface dependency. I'm guessing if you use the get method you'll probably have to allow the requests on your backend.

@max-anders
Copy link

max-anders commented Oct 28, 2024

@Remy2701

I have the same problem. Have you found a solution?

I've noticed that in my case only PNG images fails to load properly
but everything seems to work fine in release mode for now

@cedvdb
Copy link

cedvdb commented Nov 15, 2024

@rayliverified

Did you try what you suggested ?

@TrSaka
Copy link

TrSaka commented Nov 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants