1

I am using SDWEBIMAGE library for show images in ImageView in my app.

I am stuck in find unique file path of stored image in cache by SDWEBIMAGE. I need a file path of particular Image w.r.t it's URL in cached images in Document Directory of app.

So, imagepath must be unique for every URL.

I was go through this This Discussion link But no luck.

Any help will be appreciated.

Vishal Sharma
  • 1,733
  • 2
  • 12
  • 32

2 Answers2

2

From the documentation:

To lookup the cache, you use the queryDiskCacheForKey:done: method. If the method returns nil, it means the cache doesn't currently own the image. You are thus responsible for generating and caching it. The cache key is an application unique identifier for the image to cache. It is generally the absolute URL of the image.

SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
 [imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image)
 {
     // image is not nil if image was found
 }];

UPDATE

You can get the path to your image like this:

NSString *myImgKey;//this is the key for the image you want the path for
[[SDImageCache sharedImageCache] defaultCachePathForKey:myImgKey];

in case you do not use the default location, you can use:

- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;

This function returns the path for a certain key, but you will have to pass it your cache's root folder.

Daniel
  • 20,420
  • 10
  • 92
  • 149
  • [imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) Gives me "image", But how can i get PATH of each image?? – Vishal Sharma Oct 07 '14 at 11:05
  • However, that you need the path tells me that you may be doing something the difficult way. What are you intending to do? – Daniel Oct 08 '14 at 07:15
  • I want to Do OPEN IN Functionality in My app. Though I have done it by different way, I want to learn about path of Images w.r.t it's URL. It looks Ok so i am giving UPVOTE to it. After test it, If it works well then i will accept your answer. – Vishal Sharma Oct 08 '14 at 07:22
  • Hallo simplebob, The Method you have suggested is Private Method. So How can i access name of images from Other Class?? – Vishal Sharma Oct 08 '14 at 12:49
  • @SharmaVishal I have rechecked, the functions are not private? which one do you think is private? – Daniel Oct 08 '14 at 13:16
  • (remember that in ObjC `-`at the start of the function declaration just means "not static") – Daniel Oct 08 '14 at 13:19
1

SDwebImage always encrypt your image name. But if you want to access the image you can use your URL as the key to read the image from SDWebImage (- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;). See the SDWebImageCache.

https://github.com/rs/SDWebImage/blob/master/SDWebImage/SDImageCache.h

Still if you want to access the path you can create the category of SDWebImageCache and use private method

  • (NSString *)defaultCachePathForKey:(NSString *)key

See - How to get filesystem path to image cached with SDWebImage (iOS)

Community
  • 1
  • 1