I download images from Parse, and sometimes the fetch result get more errores than images get. That's the code I use to download the images:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
*PFQuery *query = [PFQuery queryWithClassName:albumToLoad];
NSArray *objectsPFFounded=[NSArray arrayWithArray:[query findObjects]];
int count= [objectsPFFounded count];
int i=0;
while (i<count){
PFFile *userImageFile = [objectsPFFounded objectAtIndex:i][@"imageFile"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
if (!self.imagesGallery) {
self.imagesGallery = [NSMutableArray arrayWithObject:[UIImage imageWithData:imageData]];
}else{
[self.imagesGallery addObject:[UIImage imageWithData:imageData]];
}
}
}];
i++;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self updateCollectionViewWhenBackgroundDone];
});
});
I get as well this error from console:
Could not save HTTP response body to /var/mobile/Applications/D96AFE9B-17EF-4630-8608-423D721394F3/Library/Caches/Parse/PFFileCache/578df836-a12c-4e70-b389-033efa647ee5-28.jpg: Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" UserInfo=0x16ed58a0 {NSSourceFilePathErrorKey=/private/var/mobile/Applications/D96AFE9B-17EF-4630-8608-423D721394F3/tmp/PFHTTPCommand0x16ddd220, NSUserStringVariant=( Move ),
NSFilePath=/private/var/mobile/Applications/D96AFE9B-17EF-4630-8608-423D721394F3/tmp/PFHTTPCommand0x16ddd220, NSDestinationFilePath=/var/mobile/Applications/D96AFE9B-17EF-4630-8608-423D721394F3/Library/Caches/Parse/PFFileCache/578df836-a12c-4e70-b389-033efa647ee5-28.jpg, NSUnderlyingError=0x16ee8350 "The operation couldn’t be completed. File exists"}
Have I to delete temp directory or cache directory before do the objects fetching? How can I solve this?
Thanks
Cocoa error 516 means that a file already exists. In your case, it seems that the image file already exists in the local cache.
You can try to check with isDataAvailable() first before you call getDataInBackgroundWithBlock.
Also, I believe this is warning should be a bug in parse. Be sure you are using the latest version of the parse framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With