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

Getting file path of image cached on disk #339

Closed
lammertw opened this issue Mar 19, 2013 · 5 comments
Closed

Getting file path of image cached on disk #339

lammertw opened this issue Mar 19, 2013 · 5 comments

Comments

@lammertw
Copy link

If would be nice if there was an easy way to get the file path of an image that is cached on disk. It could be as easy as making the cachePathForKey: method in SDImageCache public.

The reason why I personally need it is for the UIDocumentInteractionController to share images with other apps. This class requires the file path to an image. Also it requires a png extension of the file.

@gardnermj
Copy link

I'll second this, or alternatively a method similar to queryDiskCacheForKey that returns the bare NSData from the disk cache:

- (void)queryOnlyDiskCacheForKey:(NSString *)key done:(void (^)(NSData *data, SDImageCacheType cacheType))doneBlock {
    if (!doneBlock) return;

    if (!key)
    {
        doneBlock(nil, SDImageCacheTypeNone);
        return;
    }

    dispatch_async(self.ioQueue, ^
    {
        NSData *data = [NSData dataWithContentsOfFile:[self cachePathForKey:key]];

        dispatch_async(dispatch_get_main_queue(), ^
        {
            doneBlock(data, SDImageCacheTypeDisk);
        });
    });
}

@pattrawoots
Copy link

I also would like SDWebImage to allow to get file path of image cached on disk. Exactly the same reason as @lammertw

@hlcfan
Copy link

hlcfan commented Feb 17, 2014

ya, I need this method too.

@deni2s
Copy link

deni2s commented Feb 20, 2014

I also need it.

@mkll
Copy link

mkll commented Mar 29, 2014

There are private SDImageCache methods to get filesystem path to image. Just make these methods public with category. Put the code below into the SDImageCache+Private.h and add it to your project:

#import "SDImageCache.h"

@interface SDImageCache (PrivateMethods)

- (NSString *)defaultCachePathForKey:(NSString *)key;
- (NSString *)cachedFileNameForKey:(NSString *)key;

@end

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

6 participants