将图像上传到Parse

时间:2015-03-19 15:06:36

标签: ios objective-c parse-platform

我尝试将图片作为PFFile上传给我在Parse中的用户。我没有收到任何错误,但文件不存在?我做错了什么?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.imageToUpload = info[UIImagePickerControllerOriginalImage];
    self.profileImageView.image = self.imageToUpload;

    NSData *pictureData = UIImagePNGRepresentation(self.imageToUpload);

    PFFile *image = [PFFile fileWithName:@"img" data:pictureData];
    [image saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            PFUser *user = [PFUser currentUser];
            user[@"picture"] = image;
            [picker dismissViewControllerAnimated:YES completion:nil];
        }
        else {
            [[[UIAlertView alloc] initWithTitle:@"Error" message:[error userInfo][@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
        }
    } progressBlock:^(int percentDone) {
        NSLog(@"Uploaded: %d%%", percentDone);
    }];
}

1 个答案:

答案 0 :(得分:3)

您实际上并未保存user,因此用户与新文件之间的链接尚未生成。这使得文件浮动而没有连接到任何东西。

基本上,请在设置user后保存[@"picture"] = image