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

查看:94
本文介绍了从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上传到Parse

  • 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

这是什么代码看起来像;请原谅它现在在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天全站免登陆