Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.43k stars 654 forks source link

HTTP request failed, statusCode: 504 but works fine on Browser #757

Open bismarabia opened 2 years ago

bismarabia commented 2 years ago

I have the following image

https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg

It works fine on browser

image

but not using this lib

CachedNetworkImage(
        imageUrl: "https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg",
        imageBuilder: (context, imageProvider) => Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
              bottomRight: const Radius.circular(20),
              bottomLeft: const Radius.circular(20),
              topLeft: Radius.circular(isMultiImages ? 20 : 0),
              topRight: Radius.circular(isMultiImages ? 20 : 0),
            ),
            image: DecorationImage(fit: BoxFit.cover, image: imageProvider),
          ),
        ),
        progressIndicatorBuilder: (context, url, progress) => Center(
          child: CircularProgressIndicator(value: progress.progress),
        ),
        errorWidget: (context, url, error) => const Icon(Icons.broken_image),
      );

and gives the following error:

======== Exception caught by image resource service ================================================
The following HttpExceptionWithStatus was thrown resolving an image codec:
HttpException: Invalid statusCode: 504, uri = https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg

When the exception was thrown, this was the stack: 
Image provider: CachedNetworkImageProvider("https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg", scale: 1.0) 
 Image key: CachedNetworkImageProvider("https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg", scale: 1.0): CachedNetworkImageProvider("https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg", scale: 1.0)
====================================================================================================

Here is my flutter doctor output

[√] Flutter (Channel beta, 3.1.0-9.0.pre, on Microsoft Windows [Version 10.0.19044.1706], locale en-US)
    • Flutter version 3.1.0-9.0.pre at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f28e570c8c (11 days ago), 2022-06-14 13:39:33 -0500
    • Engine revision 74ee6b5afd
    • Dart version 2.18.0 (build 2.18.0-165.1.beta)
    • DevTools version 2.14.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\dsfs\AppData\Local\Android\sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: C:\Program Files\Android\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.2.32516.85
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 3.5)
    • Android Studio at D:\Softwares\android-studio
    • Flutter plugin version 34.0.2
    • Dart plugin version 183.5901
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Android Studio (version 4.1)
    • Android Studio at C:\Users\dsfs\OneDrive\Documents\EGDownloads\Compressed\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Android Studio (version 4.2)
    • Android Studio at C:\Program Files\Android\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] IntelliJ IDEA Ultimate Edition (version 2018.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.54.1)
    • VS Code at C:\Users\dsfs\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1706]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 103.0.1264.37

[√] HTTP Host Availability
    • All required HTTP hosts are available

Any idea how to overcome or fix this?

alexaung commented 2 years ago

Do you solve this issue?

bismarabia commented 2 years ago

@alexaung Not yet

Not sure the source of the issue, but it seems to be not directly related to this lib... as the same issue persists using simple http.get() request.

SupremeDeity08 commented 1 year ago

The given image seems to work as intended without any issues for me. The issue might be related to a number of problems, for example a proxy/vpn issue.

While this works for me without any headers, you should try passing some headers, for example try passing a 'Referer' header with a value of 'gardeningknowhow.com' and maybe a user-agent header too if that doesn't work.

CachedNetworkImage(
        headers: {"Referer": "gardeningknowhow.com"},
        imageUrl: "https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg",
      );
Chralu commented 4 weeks ago

Hi,

this seems related to #820. Here is a workaround proposal : https://github.com/Baseflow/flutter_cached_network_image/issues/820#issuecomment-2298422146