SDWebImageDownloader cann't cache image to disk

Created on 6 Jan 2016  路  4Comments  路  Source: SDWebImage/SDWebImage

Hi!
I want to download a picture with [SDWebImageDownloader].The result is correct.but i cannot find this file in the disk. Using SDWebImage (3.7.3)
my code:

[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
                                                              options:SDWebImageDownloaderContinueInBackground
                                                             progress:nil
                                                            completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
NSLog(@"e[%@][%d]", error, finished);
                                                            }];

Console log:
e[(null)][1]

Thanks in advance !

Most helpful comment

@mythodeia
Thanks a lot for your answer.

but I have another question.
Use this method [m1]

[imageView sd_setImageWithURL:url placeholderImage:nil options:SDWebImageRefreshCached progress:nil completed:nil]

save file to below path [p1]
/Caches/projectname/fsCachedData

but use this method below [m2]

[[SDImageCache sharedImageCache] storeImage:image forKey:imageURL];

save file here. [p2]
/Caches/default/com.hackemist.SDWebImageCache.default/

The two pathes are different. I cannot use method [m1] to set the picture which is downloaded by method [m2]

All 4 comments

the SDWebImageDownloader does not cache the image. you can cache the image in the completion using something like
[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];

@mythodeia
Thanks a lot for your answer.

but I have another question.
Use this method [m1]

[imageView sd_setImageWithURL:url placeholderImage:nil options:SDWebImageRefreshCached progress:nil completed:nil]

save file to below path [p1]
/Caches/projectname/fsCachedData

but use this method below [m2]

[[SDImageCache sharedImageCache] storeImage:image forKey:imageURL];

save file here. [p2]
/Caches/default/com.hackemist.SDWebImageCache.default/

The two pathes are different. I cannot use method [m1] to set the picture which is downloaded by method [m2]

the sd_setImageWithURL:url method caches the image without adding any extra code.
only when using the [[SDWebImageDownloader sharedDownloader] downloadImageWithURL you need to cache the image manually

the fsCachedData is not where this library caches images. This is created from the use of NSURLCache

The following code will remove all cached data from that folder:
[[NSURLCache sharedURLCache] removeAllCachedResponses];

@doingy Might be a little late but I was having the same problem as you.

My problem was that the key I was passing in had a folder structure (e.g. folder1/folder2/imageName.png) and SDWebImage didn't create the folders to store the image in so it failed.

I added this in the SDImageCache.m in the disk storeImageDataToDisk method after cachePathForKey

// creates folders for folder passed in key
NSString *cachePathForKeyFolder = [cachePathForKey stringByDeletingLastPathComponent];

if (![_fileManager fileExistsAtPath: cachePathForKeyFolder]) {
    [_fileManager createDirectoryAtPath: cachePathForKeyFolder withIntermediateDirectories:YES attributes:nil error:NULL];
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpstro02 picture rpstro02  路  3Comments

Ricardo1980 picture Ricardo1980  路  6Comments

ToLengSon picture ToLengSon  路  3Comments

devshen picture devshen  路  6Comments

halilyuce picture halilyuce  路  4Comments