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

Using LocalFileImageDataProvider not working after a while #2199

Open
ElrB opened this issue Jan 17, 2024 · 2 comments
Open

Using LocalFileImageDataProvider not working after a while #2199

ElrB opened this issue Jan 17, 2024 · 2 comments

Comments

@ElrB
Copy link

ElrB commented Jan 17, 2024

Hi

I store my images to file manager manually then use kingfisher's LocalFileImageDataProvider to load it onto ui image view. It was working perfectly for a few days until it wasn't. Currently, setting image using LocalFileImageDataProvider, image is nil, while image file still exist.

I was wondering if there is a certain duration that LocalFileImageDataProvider works or?

Below is my code:

let options = [.keepCurrentImageWhileLoading, .loadDiskFileSynchronously]

private func fetchStoredImage(using filePath: String) {
        let url = URL(fileURLWithPath: filePath)
        let provider = LocalFileImageDataProvider(fileURL: url)
        self.imageView.kf.setImage(with: provider, options: self.options)
}

Below function returns true, image still exist.

func isImageSaved(atFileName fileName: String, completion: @escaping (Bool) -> Void) {
        getFilePath(forFileName: fileName) { filePath in
            guard let filePath = filePath else {
                completion(false)
                return
            }
            
            let fileManager = FileManager.default
            completion(fileManager.fileExists(atPath: filePath))
        }
 }
@ElrB
Copy link
Author

ElrB commented Feb 23, 2024

@onevcat please assist. Thanks.

@onevcat
Copy link
Owner

onevcat commented Feb 28, 2024

@ElrB Sorry for the late reply.

I don't think there is a "certain duration that LocalFileImageDataProvider works"...Regardless of a local data provider or a remote URL data fetching, both are working in similar ways: Check the cache, if not hit, then get the data from the origin place (the local file or URL) and cache the image.

From your description, it seems that once the cache is expired, it stops loading from the original local file. It should not happen.

I also tried to build a simple sample with LocalFileImageDataProvider and a very short disk cache expiration duration (to simulate your case), but I cannot reproduce it at all.

Can you try:

  1. Make sure that the url you use in fetchStoredImage has exactly the same path as you get in isImageSaved.
  2. Try to print some result to see if there is an error and/or where the image is from when you set it.
self.imageView.kf.setImage(with: provider, options: self.options) { result in
  switch result {
    case .success(let r):
      print(r.cacheType)
      print(r.source)
    case .failure(let error):
      print(error)
  }
}

By the way, you can use the .diskCacheExpiration option change the disk cache duration to a smaller value to boost the verification.

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

2 participants