Search code examples
ioscachingparse-platformpffile

How to get PFFile from disk?


I want to get a PFFile from disk. I learned here that Parse caches all PFFiles as they are downloaded. I am wondering now how to retrieve that cache. What is the correct path. The path I use is suggested here

NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0] stringByAppendingFormat:@"/Caches/Parse/PFFileCache/%@", pffile.name];

NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];

data is always nil.

Am I using the correct path? /Caches/Parse/PFFileCache/


Solution

  • From your description of the problem you should use a slightly different process. Use the PFFile interface initially, but then store the urls from the files for the case where you need to access the file data later. In this way you have a direct link to the file data and can use a normal connection or session to download.

    If you don't actually need the PFFile for anything about the download then using the REST interface may be more suitable for you.

    Another alternative is to make the same request which originally returned the file information to you, but instructing the API to use cached information only. This is done by setting cachePolicy to CACHE_ONLY on your PFQuery.