How to send users a photo with Parse?

114 views Asked by At

I have set up an imageView in Xcode with a image from the camera roll and I want to be able to send this photo to other users that are already in the current user's friend list. I understand how to generally upload the photo, but I don't really know how the photo is associated to the user and sent to the list of friends that the user selects. I tried to use a PFQuery but I get error messages every time I try to follow the AnyPic example on Parse's website. (The error comes off of the KPAP forkey that Xcode can't find)

The code I have works for sending a photo to the Parse server, but I don't think that the code I have is associated with the user who sent it, and it doesn't work for sending a list of people the code.

PFObject * newImage = [PFObject objectWithClassName:@"collectionView"];
NSData * imageData = UIImageJPEGRepresentation(imageView.image, 1.0f);
PFFile * newImageFile = [PFFile fileWithName:@"picture.jpeg" data:imageData];
[newImage setObject:newImageFile forKey:@"imageFile"];
[newImage saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

    if(!error)
    {
        NSLog(@"sucess");

    }
}];

Any help would be greatly beneficial to me!

2

There are 2 answers

0
Mahendra On BEST ANSWER

After looking your code, you just save the image in cloud and you neither specify who uploaded it and who can access it(Read and Write Permission is not set).

By default, whatever you are storing in parse cloud, the ACL(Access Control List) is Public Read, Write.

So, If you want to associate a user who upload a image, you can use like below.

//it will return the current user detail
PFUser *currentUser = [PFUser currentUser];

PFFile * newImageFile = [PFFile fileWithName:@"picture.jpeg" data:imageData];

//Assign image to current user
currentUser[@"image"] = newImage; 

[currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
           //success
        } else if (error) {
           //error
        }
}];

You can use PFRole or PFACL to give the access to other users.

0
iForests On

If I understand your question correctly, you need to add a new column "user" to associate the image and the user who sent it.

[newImage setObject:[PFUser currentUser] forKey:@"user"];
[newImage setObject:newImageFile forKey:@"imageFile"];
[newImage saveInBackgroundWithBlock...