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

CacheManager: Failed to download file from url #336

Open
sandeep9607 opened this issue Feb 12, 2020 · 105 comments
Open

CacheManager: Failed to download file from url #336

sandeep9607 opened this issue Feb 12, 2020 · 105 comments

Comments

@sandeep9607
Copy link

cached_network_image: ^2.0.0

I/flutter (23961): CacheManager: Failed to download file from http://host/images/a.png with error:
I/flutter (23961): SocketException: Failed host lookup: 'host' (OS Error: No address associated with hostname, errno = 7)

@sandeep9607
Copy link
Author

Flutter 1.12.13+hotfix.7

Any help would be appreciable.
Thanks

@samuelematias
Copy link

samuelematias commented Feb 12, 2020

I'm have the same issue:

flutter: CacheManager: Failed to download file from https://static-images.api.com.br/image/upload/f_auto,t_thumbnail/icones/pgto/******** with error: HttpException: No valid statuscode. Statuscode was 404

Flutter Version:
Flutter 1.12.13+hotfix.7 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9f5ff2306b (2 weeks ago) • 2020-01-26 22:38:26 -0800 Engine • revision a67792536c Tools • Dart 2.7.0

Plugin Version:
cached_network_image: ^2.0.0

@taekungkub
Copy link

i have this same problam

@renefloor
Copy link
Contributor

@sandeep9607 @samuelematias or @taekungkub can any of you give me a valid URL that does load in the browser (and doesn't give a 404), but does not load in the CachedNetworkImage?

@renefloor renefloor assigned renefloor and unassigned renefloor Feb 21, 2020
@renefloor renefloor added status: needs more info We need more information before we can continue work on this issue. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels and removed status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels labels Feb 21, 2020
@dodancs
Copy link

dodancs commented Mar 21, 2020

I have some similar issue:

CacheManager: Failed to download file from URL with error:
  type '(HttpException) => Null' is not a subtype of type '(dynamic) => dynamic'

First time using the package, it took like 5 reloads of my app to successfully display the image...

  • Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale sk-SK)
  • cached_network_image: ^2.0.0

@dodancs
Copy link

dodancs commented Mar 21, 2020

I have some similar issue:

CacheManager: Failed to download file from URL with error:
  type '(HttpException) => Null' is not a subtype of type '(dynamic) => dynamic'

First time using the package, it took like 5 reloads of my app to successfully display the image...

  • Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale sk-SK)
  • cached_network_image: ^2.0.0

This only happened when using an Emulator to run my app. When I switched to my physical device, the errors did not appear.... this is strange. I also tried disabling Proxy settings on the android emulator, but with no change.

@jawad12345A
Copy link

Does anyone solved this issue?

@renefloor
Copy link
Contributor

@dodancs that is really strange, as far as I know an emulator works the same as a physical device.

@dodancs
Copy link

dodancs commented Mar 31, 2020

@renefloor Doesn't seem like it. I'm not sure what could be causing this. But I spent a lot of hours trying to fix my "broken code" to only realize it was because of the emulator. I also never seen anything like this before.

@jawad12345A
Copy link

@renefloor Doesn't seem like it. I'm not sure what could be causing this. But I spent a lot of hours trying to fix my "broken code" to only realize it was because of the emulator. I also never seen anything like this before.

It is also happening on physical phone too

@hasanzia1993
Copy link

same issue CacheManager: Failed to download file from ...

@DhavalRKansara
Copy link

is there any solution for this or I also have to write "the SAME ISSUE"

@hasanzia1993
Copy link

hasanzia1993 commented Apr 9, 2020

same issue CacheManager: Failed to download file from ...

It actually is working fine for me now, my URL was not returning any data first. Could be something else for other but for me it's working perfectly fine now.

@renefloor
Copy link
Contributor

is there any solution for this or I also have to write "the SAME ISSUE"

@DhavalRKansara you could help in looking for a solution. I don't know why files sometimes fail to download, as I still don't have a reproducible example of an url that should work but doesn't

@DhavalRKansara
Copy link

DhavalRKansara commented Apr 16, 2020

@renefloor Actually You guys can add one null and empty check before network request for the image and if image URL is null then simply show the placeholder image means no need to do network request for null image URL.

Because in my case I have some image URL as null or empty and then I am getting the error:

flutter: CacheManager: Failed to download file from null with error:
Invalid argument(s): No host specified in URI null

@renefloor
Copy link
Contributor

Hmm, not sure if I agree with that. Why the placeholder and not the error widget? I would expect an error when the image is null. What is your usecase that null is a valid image?

@DhavalRKansara
Copy link

Hmm, not sure if I agree with that. Why the placeholder and not the error widget? I would expect an error when the image is null. What is your use case that null is a valid image?

Yeah totally agree we can show error image In case of null or empty image URL.

@DhavalRKansara
Copy link

DhavalRKansara commented Apr 17, 2020

This is really Strange, Now I am also facing the same issues while downloading the images.

In my case, I have to pass httpHeader with AuthToken to download the image using this library. Also, I am getting the error every time sometimes it successfully download the image and sometimes it gives the below error. It's really strange.

flutter: CacheManager: Failed to download file from https://*****?imageName=jpg file.jpg&path=Patient_Documents\ with error:
HttpException: Invalid statusCode: 500, uri = https://*****?imageName=jpg%20file.jpg&path=Patient_Documents%5C

@renefloor Have you faced the error in any example?

@renefloor
Copy link
Contributor

@DhavalRKansara a statusCode 500 normally is something going wrong on the server. I guess you have to discuss this with the backend developer. I don't know if you have content with him/her?

@DhavalRKansara
Copy link

@DhavalRKansara a statusCode 500 normally is something going wrong on the server. I guess you have to discuss this with the backend developer. I don't know if you have content with him/her?

@renefloor Yes I have discussed with my backend developer and also for the same URL I have tried to get an image through the postman and I successfully get the image in postman. That's why I am saying that not every time I got failed to download network image it's 50-50 scenario and still I'm looking into it with different testing scenarios.

@DhavalRKansara
Copy link

cached_network_image: ^2.0.0

I/flutter (23961): CacheManager: Failed to download file from http://host/images/a.png with error:
I/flutter (23961): SocketException: Failed host lookup: 'host' (OS Error: No address associated with hostname, errno = 7)

Please check the image file url carefully... Because I don't found any image for the given url.

@ivenxu
Copy link

ivenxu commented May 3, 2020

In my case, add

<uses-permission android:name="android.permission.INTERNET"/>

to android/app/src/main/AndroidManifest.xml worked.

@hahazheng
Copy link

@renefloor @DhavalRKansara

flutter: CacheManager: Failed to download file from http://mt3.google.com/vt/lyrs=m&x=32752&y=21795&z=16 with error:
SocketException: OS Error: Operation timed out, errno = 60, address = mt3.google.com, port = 52998
Example url:
http://mt3.google.com/vt/lyrs=m&x=32752&y=21795&z=16

@renefloor
Copy link
Contributor

Operation timed out sounds like a bad internet connection.

@cargallo
Copy link

image

image

Same Issue here! I want to test whats would happen if the url is wrong. In the case of firebase storage it returns 403. But the problem is thtat I don't know why the debugger is stopping there since I think it should be a Controlled Exception..

@ronniechew
Copy link

We have been getting images from a repository and sometimes some images doesn't exist. We show a default image in those cases. We don't want our console logs to be cluttered with so much noise about the same error over and over again.

There are so many folks complaining about it so I am not sure why nobody from maintainers is looking to understand it. We can handle exceptions, errors and print whatever we want but this is a very valid scenario and let us handle it based on our use case.

I noticed earlier issues were also closed without resolution #273

Exactly same issue here.
The problem isn't being network issue or image temporary not available.
Sometimes the image URL simply expired or entered wrongly for some reason.

In that scenario, I'd expect the plugin to render errorWidget and silent the error.

Imagine you have a list of 10+ invalid image links, every time you hot-reload this list you need to click 10+ times continue on the debugger to do debugging...

IMHO the plugin should gracefully handle invalid image URL error if errorWidget is provided, otherwise throw error as it is.

Thanks for the great plugin though :)

@harithwick
Copy link

Same issue here. the app seems to be crashing in production due to cached_network_image. Im playing around with https://pub.dev/packages/optimized_cached_image/ lets see how that goes

@Giuliopretis
Copy link

The issue still remains, and the odd thing is that happens only on certain devices.

@zbahadir
Copy link

I think most problems seem to be with non-english file naming. I've never had a problem with image files named only in English.

Is there any solution about this?

@vigdora
Copy link

vigdora commented Apr 20, 2022

the app is probably crashing in production for me as well for the same reason -
I am getting this report in Crashlytics (FATAL) for multiple users now
image
is there a way to walk around it i.e - like adding some sort of try & catch (I tried Try/catch but obviously it didn't work for me)

@ronniechew
Copy link

the app is probably crashing in production for me as well for the same reason - I am getting this report in Crashlytics (FATAL) for multiple users now image is there a way to walk around it i.e - like adding some sort of try & catch (I tried Try/catch but obviously it didn't work for me)

Yes this is getting annoying... Even try catch wouldn't suspend the error.

Is there anyone able to help look into this please?

@ken-ng-esotec
Copy link

I also experienced this issue, and could not find a flutter way to solve the 404 issue which crashes the app.

As a solution, I am using imagekit as a CDN and we can tell imagekit to display a default image if the original image is missing: https://docs.imagekit.io/features/default-images

@hasanmhallak
Copy link

hasanmhallak commented May 18, 2022

Thanks for this great plugin.

But why the console is cluttered with all that exceptions even if I provided an error builder?
I have a list of users with like 20+ image and this is very annoying.

@vigdora
Copy link

vigdora commented May 30, 2022

I managed to reproduce the error locally - and I have a more descriptive logs from crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HttpException: Invalid statusCode: 403, uri = https://hiding-the-real-url loading image. Error thrown Non-Fatal error occured [Unhandled Error].
at CachedNetworkImage._octoErrorBuilder(cached_image_widget.dart:319)
at ImageHandler._errorBuilder(image_handler.dart:299)
at _ImageState.build(image.dart:1266)
at StatefulElement.build(framework.dart:4870)
at ComponentElement.performRebuild(framework.dart:4754)
at StatefulElement.performRebuild(framework.dart:4928)
at Element.rebuild(framework.dart:4477)
at BuildOwner.buildScope(framework.dart:2659)
at WidgetsBinding.drawFrame(binding.dart:882)
at RendererBinding._handlePersistentFrameCallback(binding.dart:363)
at SchedulerBinding._invokeFrameCallback(binding.dart:1144)
at SchedulerBinding.handleDrawFrame(binding.dart:1081)
at SchedulerBinding._handleDrawFrame(binding.dart:995)

can anyone from the contributors look at this?

@saharvx9
Copy link

I managed to reproduce the error locally - and I have a more descriptive logs from crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: HttpException: Invalid statusCode: 403, uri = https://hiding-the-real-url loading image. Error thrown Non-Fatal error occured [Unhandled Error].
at CachedNetworkImage._octoErrorBuilder(cached_image_widget.dart:319)
at ImageHandler._errorBuilder(image_handler.dart:299)
at _ImageState.build(image.dart:1266)
at StatefulElement.build(framework.dart:4870)
at ComponentElement.performRebuild(framework.dart:4754)
at StatefulElement.performRebuild(framework.dart:4928)
at Element.rebuild(framework.dart:4477)
at BuildOwner.buildScope(framework.dart:2659)
at WidgetsBinding.drawFrame(binding.dart:882)
at RendererBinding._handlePersistentFrameCallback(binding.dart:363)
at SchedulerBinding._invokeFrameCallback(binding.dart:1144)
at SchedulerBinding.handleDrawFrame(binding.dart:1081)
at SchedulerBinding._handleDrawFrame(binding.dart:995)

can anyone from the contributors look at this?

It happens to me yesterday too plss fix itt

@vigdora
Copy link

vigdora commented Jun 1, 2022

will someone take a look at this?

@lnwfern13
Copy link

add comment
file web_help.dart in flutter_cache_manager 3.3.0

// if (!hasNewFile && !keepOldFile) {
// throw HttpExceptionWithStatus(
// response.statusCode,
// 'Invalid statusCode: ${response.statusCode}',
// uri: Uri.parse(cacheObject.url),
// );
// }

and chang file _image_loader.dart in cached_network_image 3.2.1

catch (exception, stack) {
// Depending on where the exception was thrown, the image cache may not
// have had a chance to track the key in the cache at all.
// Schedule a microtask to give the cache a chance to add the key.
scheduleMicrotask(() {
evictImage();
});
chunkEvents.addError(exception, stack);
//rethrow;
}

@dcg123
Copy link

dcg123 commented Jul 4, 2022

在flutter_cache_manager 3.3.0 中添加注释文件web_help.dart

// if (!hasNewFile && !keepOldFile) {

// throw HttpExceptionWithStatus(
// response.statusCode,
// 'Invalid statusCode: ${response.statusCode}',
// uri: Uri.parse(cacheObject.url),
/ /);
// }

并在 cached_network_image 3.2.1 中更改文件 _image_loader.dart

catch (exception, stack) {

// 根据抛出异常的位置,图像缓存可能根本没有
机会跟踪缓存中的键。
// 调度一个微任务,让缓存有机会添加密钥。
scheduleMicrotask(() {
evictImage();
});
chunkEvents.addError(异常,堆栈);
//重新抛出;
}

Thank you very much, it solved my problem, thumbs u

@amitBlueVine
Copy link

This is a really good package, I would hate to switch to a different one.
Can someone from the contributors please have a look?

@dgurudot
Copy link

dgurudot commented Oct 11, 2022 via email

@felix-larsen
Copy link

For crashlytics as a workaround you can filter for this Error before actually sending it to crashlytics like this:

FlutterError.onError = (flutterErrorDetails) async {
    if (flutterErrorDetails.library == "image resource service" &&
        flutterErrorDetails.exception
            .toString()
            .startsWith("HttpException: Invalid statusCode: 404, uri")) {
      return;
    }
    await FirebaseCrashlytics.instance
        .recordFlutterFatalError(flutterErrorDetails);
    return;
};

@Amshaf123
Copy link

PS C:\Users\User\Desktop\OKD\okd> flutter run
Launching lib\main.dart on CPH2387 in debug mode...
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:1: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
cimport 'dart:async';
^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:1: Error: Expected ';' after this.
cimport 'dart:async';
^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:9: Error: Expected a declaration, but got ''dart:async''.
cimport 'dart:async';
^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:1:21: Error: Unexpected token ';'.
cimport 'dart:async';
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:2:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'dart:typed_data';
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:3:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'dart:ui' as ui;
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:4:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'dart:ui';
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:6:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:7:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'package:flutter/material.dart';
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:8:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:10:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'package:cached_network_image_platform_interface'
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:13:1: Error: Directives must appear before any declarations.
Try moving the directive before any declarations.
import 'package:cached_network_image_platform_interface'
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:24:5: Error: Type 'StreamController' not found.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:53:7: Error: Type 'StreamController' not found.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:83:5: Error: Type 'StreamController' not found.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:24:5: Error: 'StreamController' isn't a type.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:53:7: Error: 'StreamController' isn't a type.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:83:5: Error: 'StreamController' isn't a type.
StreamController chunkEvents,
^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart:129:7: Error: The method 'scheduleMicrotask' isn't defined for the class 'ImageLoader'.

  • 'ImageLoader' is from 'package:cached_network_image/src/image_provider/_image_loader.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/cached_network_image-3.2.3/lib/src/image_provider/_image_loader.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'scheduleMicrotask'.
    scheduleMicrotask(() {
    ^^^^^^^^^^^^^^^^^
    Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

  • Where:
    Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1201

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 17s how to solve this error

@EarningsCall
Copy link

For crashlytics as a workaround you can filter for this Error before actually sending it to crashlytics like this:

FlutterError.onError = (flutterErrorDetails) async {
    if (flutterErrorDetails.library == "image resource service" &&
        flutterErrorDetails.exception
            .toString()
            .startsWith("HttpException: Invalid statusCode: 404, uri")) {
      return;
    }
    await FirebaseCrashlytics.instance
        .recordFlutterFatalError(flutterErrorDetails);
    return;
};

I believe this works for solving firebase crashes, but there is another problem:

If you have a given URL, say example.com/image-123.png

and server returns 404, then the cache library will try to load that image over and over again, even if same response is always HTTP 404.

According to HTTP specifications, 4XX errors means some sort of client error, and therefore the problem is the request, not the server. You shouldn't retry the same request for 4XX errors because I'd expect the same response each time. Therefore, the cache library should store the result (HTTP 404) and return that instead.

@EarningsCall
Copy link

has anyone in the community found an alternative library that properly caches HTTP 4XX results?

@ggirotto
Copy link

It's so sad that the maintainers doesn't consider this as an issue

@ridwanulhoquejr
Copy link

It's been 4 years, but they still don't acknowledge this as an issue!!!

@flying-lantern
Copy link

I just found this library and ran into this issue. It is pretty disappointing that the developers fail to acknowledge this as a problem. For some reason or the other an invalid URL can be provided where the reasonable expectation would be for the error widget to be rendered in the image's place. It's a shame the developers have taken this stance. The plugin is otherwise great.

@danial2026
Copy link

apparently, the issue is in newer versions of Flutter. I found out that Flutter 3.10.6 works without any issues.
(If your app is dependent on newer versions, you are out of luck.)
and obviously, versions older than 3 won't work either.

@zhuyuzhu
Copy link

zhuyuzhu commented Mar 8, 2024

3.3.1 Still have this problem

@Mohit8G
Copy link

Mohit8G commented Mar 11, 2024

https://medium.com/@rishyash8/flutter-firebase-crash-report-because-of-connection-closed-before-full-header-was-received-7ace6e84bc5d
https://medium.com/@rishyash8/how-to-load-network-image-in-flutter-with-retry-functionality-837db9809662

this might help

@BenjaminStoeberl
Copy link

BenjaminStoeberl commented Jun 19, 2024

According to the changelog, with CachedNetworkImage version 3.3.1 errors are no longer reported to the global error handler if you add an errorListener.

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