I'm writing an application that allows the users to take and store images on Parse. Thus far I've managed to accomplish saving the image array to Parse by using the following logic:
- Take Image
- Add Object to Array
- Convert array to NSData
- Convert NSData to PFFile
- Set file upload destination (via unique objectId)
- Upload PFFile to Parse
This is what the code looks like; please forgive the fact that it's in dismissViewController for now, I'm only trying to get it to save successfully:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
_takenImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^
{
// Add object to array: Working
[_tankImagesArray addObject:_takenImage];
NSLog(@"Number of images taken: %lu", (unsigned long)_tankImagesArray.count);
// Convert array to NSData Object
NSData *imageData = [NSKeyedArchiver archivedDataWithRootObject:_tankImagesArray];
// Convert NSData Object to PFFile
PFFile *imageFile = [PFFile fileWithData:imageData];
PFQuery *tankQuery = [PFQuery queryWithClassName:@"SavedTanks"];
_tankObject = [tankQuery getObjectWithId:_passedValue];
[_tankObject setObject:imageFile forKey:@"tankImages"];
[_tankObject save];
}];
}
Now, my question is: How exactly would I go about retrieving that file? My ultimate goal here is to allow the user to see images they've taken in the past and add to the list of pictures in the collection and upload them to the server. I'm just unsure of how to retrieve the file once its been uploaded and make sure the integrity is maintained.
All the above solutions are correct, but want to add one another way to have support of Image Caching of SDWebImage or any library like that. On Successful completion you will be have
PFFile
, whose property "url" will return you actuall URL of Image where it is saved. You can use that to load image. Using this approach I was able to have Image Cacheing based on key as URL.Did you try:
Why would you want to download photos from parse that the user already has them locally..?
I recommend you to use : https://github.com/AFNetworking/AFNetworking
you can also save local photos to cache so you access them easily so you dont need any downloading from parse...
now if you still want to download the photos from parse just make a normal query and download all the photos parse object and you will get in the PFObject the PFFile of your photos.
Example:
In the .h file of your collection view you need to have something like below. Note that the one I built you could like an image and then sort liked images using a segment controller.
Then in the .m file of your collection view
Hope this is of some help to you.