flutter_cached_network_image
flutter_cached_network_image copied to clipboard
FileSystemException: Cannot open file, OS Error: No such file or directory, errno = 2 was thrown
π Bug Report
In my app, Im having a ListView which shows the users like in contacts app, sometimes its throws FileSystemException: Cannot open file.
ββββββββ Exception caught by image resource service ββββββββ The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/var/mobile/Containers/Data/Application/
B861D1-3A04-498D-AC67-23E00574DD1C/Library/Caches/
libCachedImageData/fdbf1150-a040-11ea-d6f9-4168d77.bin'
(OS Error: No such file or directory, errno = 2)
When the exception was thrown, this was the stack
#0 _File.open.
Code
ListTile(
leading: CachedNetworkImage(
fadeInDuration: Duration(milliseconds: 100),
fit: BoxFit.cover,
imageUrl: _filteredUser[index].photoUrl,
progressIndicatorBuilder: (context, url, downloadProgress) =>
shimmerImageTile(),
errorWidget: (context, url, error) => _imagePlaceHolder(),
),
title: userName(),
),
Configuration
Version:
cached_network_image: ^2.2.0
Platform:
- [ π’] :iphone: iOS
- [ π’] :robot: Android
Same issue if the URL is empty(''). Maybe better to show error placeholder instead of trying to load it?
Hi @fryette thanks for your response but Im handling the empty url already and I think this is problem with caching im not sure.
ya, having same problem... any solution for now?
You can find more on this issue here: https://github.com/Baseflow/flutter_cache_manager/issues/135#issuecomment-638753854
hi sorry for rushing, any status update or solution? now, the images of my app keep disappearing due to the error....
@Soon96 No sorry, maybe you can help in finding the real problem and solution. When do the images disappear mostly? Do you load a lot of images, or older images? Do you have any idea how to reproduce this issue?
When do the images disappear mostly? usually happen in listview, when scroll down the list then scroll up again... some image will missing. Do you load a lot of images, or older images? Quite a number of products images... Do you have any idea how to reproduce this issue? maybe you can test in a list view, scroll up and down....
Error Msg in Debug Console:
I/flutter (27834): Another exception was thrown: FileSystemException: Cannot open file, path = '/data/user/0/ ... /cache/libCachedImageData/ef136f60-aa2d-11ea-ab9b-1d7b0e7aa781.html' (OS Error: No such file or directory, errno = 2)
I/flutter (27834): Another exception was thrown: FileSystemException: Cannot open file, path = '/data/user/0/ ... /cache/libCachedImageData/ef1432b0-aa2d-11ea-c584-d30ca5b9f1c2.html' (OS Error: No such file or directory, errno = 2)
Error video in app: https://www.goldensticks.blog/assets/error_video.mp4
It work perfectly previously, just this few week we start facing this problem.
@renefloor is it flutter list view deleting our cache files?
The cache manager should only remove files that haven't been used today as given here: https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/storage/cache_object_provider.dart#L86
So it could be that Android or iOS thinks the cached files are to big and deletes them from the cache.
My guess is that the library handles this better in version 2.3.0-beta.1+1, as there the encoded image is cached in memory and when that is removed from memory the file is downloaded again when the file is removed as well.
But that version has some issues with scrolling if you are on the stable channel. (Fixed in beta and newer)
thanks for the reply, so for now on we can only wait for the new version stable release or change to other plugin?
You could also use the beta version, which is often pretty stable. I also found that there is a 'file.exists()' check missing here: https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/cache_store.dart#L69, so that could fix part of the problem.
Using the beta version 2.3.0-beta.1+1 recommended above causes us many of these exceptions
ββββββββ Exception caught by image resource service ββββββββββββββββββββββββββββ
The following assertion was thrown when reporting an error to an image listener:
setState() called after dispose(): _ImageState#679ff(lifecycle state: defunct, not mounted, stream: ImageStream#85a0f(MultiFrameImageStreamCompleter#5ed5d, [750Γ1061] @ 1.0x, 1 listener), pixels: null, loadingProgress: null, frameNumber: null, wasSynchronouslyLoaded: false)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
And then many of the images don't appear. Hope it will become stable soon to fix this FileSystemException
@bradsb that is a bug in the Flutter code. The fix is currently available in the beta channel. Hopefully it is soon available in stable. It is also the reason 2.3.0-rc has a minimum flutter version of 1.19.0
@renefloor I see. Thanks for the reply!
@renefloor I have changed the dependency code to develop
branch, but still got this file exception. Based on the given stack frame, I found the reason why I got file exception is the very first calling of Uri.base.scheme
, so I figured it is a flutter issue.
SDK version:
β / flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[β] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.4 19E287, locale
zh-Hans-CN)
Exception info:
I'm having the same problem, I got this error but when I try to create a File with a PickedFile path. The code is something like this: File(this.image.path) "image" is a PickedFile object I'm using flutter 1.20.2
@renefloor I have changed the dependency code to
develop
branch, but still got this file exception. Based on the given stack frame, I found the reason why I got file exception is the very first calling ofUri.base.scheme
, so I figured it is a flutter issue.SDK version:
β / flutter doctor Doctor summary (to see all details, run flutter doctor -v): [β] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.4 19E287, locale zh-Hans-CN)
Exception info:
@renefloor We finally found out the real reason now! Because Uri.base
try to access current working directory, but there is a case we called -changeCurrentDirectoryPath:
in Objective-C to change current directory path to a new path and then we removed that directory, this made current directory path become null
. Consequently, calling Uri.base
would leads a file system exception.
We fixed this issue and that file system exception doesn't come again.
Hi there!
Just updated to the 2.3.1 version and the problem with error described by @Soon96 exists on my side as well.
Just in my case the lib can't open ...libCachedImageData/<UUID>.json
@troyanskiy what's the url? It looks like the url gives a json-file and it makes sense that can't be shown as an image.
@troyanskiy what's the url? It looks like the url gives a json-file and it makes sense that can't be shown as an image.
@renefloor the backend url is image url, where there are 4 possible returns
- Status 200 with image
- Status 403 when user does not have rights
- Status 401 when no session
- Status 404 when the file is not found
So it's always or error code or the image... As far as I understand from reading your code you set file extension based on content-type from the response, so I will double check if the backend has some exceptions and returns JSON instead of image.
Thanks a lot!
@renefloor Is it possible to add some extra check somewhere if the file really exists in the cache, instead of throwing the exception?
@renefloor I have changed the dependency code to
develop
branch, but still got this file exception. Based on the given stack frame, I found the reason why I got file exception is the very first calling ofUri.base.scheme
, so I figured it is a flutter issue.SDK version:
β / flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[β] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.4 19E287, locale
zh-Hans-CN)
Exception info:
@renefloor We finally found out the real reason now! Because
Uri.base
try to access current working directory, but there is a case we called-changeCurrentDirectoryPath:
in Objective-C to change current directory path to a new path and then we removed that directory, this made current directory path becomenull
. Consequently, callingUri.base
would leads a file system exception.We fixed this issue and that file system exception doesn't come again.
ε₯们οΌζδΉζΉηοΌθ―·ζδΈ
@renefloor I have changed the dependency code to
develop
branch, but still got this file exception. Based on the given stack frame, I found the reason why I got file exception is the very first calling ofUri.base.scheme
, so I figured it is a flutter issue. SDK version:β / flutter doctor Doctor summary (to see all details, run flutter doctor -v): [β] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.4 19E287, locale zh-Hans-CN)
Exception info:
@renefloor We finally found out the real reason now! Because
Uri.base
try to access current working directory, but there is a case we called-changeCurrentDirectoryPath:
in Objective-C to change current directory path to a new path and then we removed that directory, this made current directory path becomenull
. Consequently, callingUri.base
would leads a file system exception.We fixed this issue and that file system exception doesn't come again.
@renefloor οΌhelloοΌis that problemοΌ
Im my case, it is calculating something on memory and when app restarted it works. So below is my workaround solution
class CustomCachedImage extends StatefulWidget {
final String imageUrl;
final double radius = 20.0;
CustomCachedImage({
@required this.imageUrl,
});
@override
_State createState() => _State();
}
class _State extends State<CustomCachedImage> {
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: widget.imageUrl,
imageBuilder: (context, imageProvider) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(widget.radius)),
image: DecorationImage(
image: imageProvider,
alignment: Alignment.topCenter,
fit: BoxFit.cover,
scale: 1,
),
),
);
},
placeholder: (BuildContext context, String url) => Container(),
// If error happens load image by using NetworkImage
errorWidget: (context, url, error) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(widget.radius)),
image: DecorationImage(
image: NetworkImage(widget.imageUrl),
alignment: Alignment.center,
fit: BoxFit.cover,
scale: 1,
),
),
);
},
);
}
}
what is the solution for this when im using image picker
same Issue as @noor848 when using Image Picker
what is the solution for this when im using image picker
same issue, what is the solution
We are still facing issue. Is there any update on this ?