简体   繁体   English

如何从parse.com检索图像

[英]How to retrieve image from parse.com

Hi i am new to using parse.com Actually iam trying to save image in parse.com and retriving it.. But i successfully saved image as a PFFile 嗨,我是使用parse.com的新手。实际上,我试图将图像保存在parse.com中并进行检索。。但是我成功地将图像保存为PFFile 在此处输入图片说明

in parse.com dashboard it showing like this 在parse.com仪表板中,它显示如下

在此处输入图片说明

Now how can i retrive image and show in UIImageView 现在如何检索图像并在UIImageView中显示

I tryied like this but its not working.. 我像这样试着,但没有用。

 PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"];
    [query whereKey:@"userName" containsString:@"ravi"];
    [query getObjectInBackgroundWithId:@"ID" block:^(PFObject *object, NSError *error) {
        if(!error){
            PFFile *im = [object objectForKey:@"imageFile"];
            _getImg.image = im;
        }}];

Here i want to retrive the particular image of userName ravi 在这里我想检索userName ravi的特定图像

To retrieve the image, you need to: 要检索图像,您需要:

  1. Query for the PFObject in question 查询有问题的PFObject
  2. Use -[PFFile getDataInBackgroundWithBlock:] to retrieve the PFFile 's data 使用-[PFFile getDataInBackgroundWithBlock:]检索PFFile的数据
  3. Create a UIImage with the resulting NSData 使用生成的NSData创建UIImage

     PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"]; [query whereKey:@"userName" containsString:@"ravi"]; [query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) { if (!object) { return NSLog(@"%@", error); } PFFile *imageFile = object[@"imageFile"]; [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { if (!data) { return NSLog(@"%@", error); } // Do something with the image self.imageView.image = [UIImage imageWithData:data]; }]; }]; 

As an aside, unless purely for experimentation, or you're performing some operation off of the main thread, I would avoid saving the PFObject synchronously using -[PFObject save] and use instead, the asynchronous version, -[PFObject saveInBackgroundWithBlock:] . PFObject ,除非纯粹出于实验目的,或者您正在执行主线程之外的操作,否则我将避免使用-[PFObject save]同步-[PFObject save]而应使用异步版本-[PFObject saveInBackgroundWithBlock:]

You cannot use getObjectInBackgroundWithId: method in your case. 您不能在这种情况下使用getObjectInBackgroundWithId:方法。 Instead you can use getFirstObjectInBackgroundWithBlock: method to retrieve the first instance. 相反,您可以使用getFirstObjectInBackgroundWithBlock:方法检索第一个实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM