从 Parse iOS 下载图像 [英] Downloading images from Parse iOS

查看:15
本文介绍了从 Parse iOS 下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,允许用户在 Parse 上拍摄和存储图像.到目前为止,我已经通过使用以下逻辑成功地将图像数组保存到 Parse:

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:

  • 拍照
  • 将对象添加到数组
  • 将数组转换为 NSData
  • 将 NSData 转换为 PFFile
  • 设置文件上传目的地(通过唯一的 objectId)
  • 上传 PFFile 进行解析

代码是这样的;请原谅它现在在dismissViewController中,我只是想让它成功保存:

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.

推荐答案

您是否尝试过:

PFQuery *query = [PFQuery queryWithClassName:@"SavedTanks"];
[query whereKey:@"tankImages" equalTo:@"your_image.jpg"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
  if (!error) {
    // The find succeeded.
    NSLog(@"Successfully retrieved %d images.", objects.count);
    // Do something with the found objects
    for (PFObject *object in objects) {
        NSLog(@"%@", object.objectId);
    }
  } else {
    // Log details of the failure
    NSLog(@"Error: %@ %@", error, [error userInfo]);
  }
}];

这篇关于从 Parse iOS 下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆