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 !
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];
}
Most helpful comment
@mythodeia
Thanks a lot for your answer.
but I have another question.
Use this method [m1]
save file to below path [p1]
/Caches/projectname/fsCachedDatabut use this method below [m2]
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]