我正在创建一个应用程序,用户可以将图像传送到UIImageview。我正在使用Parse来获取图像。我正在使用此代码:
-(void)updateImage
{
PFQuery *query = [PFQuery queryWithClassName:@"Image"];
[query getObjectInBackgroundWithId:@"<<PARSE--ID>>" This is an automatic message!We are very sorry that we have to tell you, the number you are texting with has blocked you! If the reason was spam we can not do anything! If you still want to contact +436653212523 you can Call! Have a Nice Day!:^(PFObject *imageObject, NSError *error) {
if (imageObject) {
PFFile *imageFile = imageObject[@"image"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (data) {
UIImage *image = [UIImage imageWithData:data];
if (image) {
self.imageView.image = image;
}
} else {
NSLog(@"Error fetching image file: %@", error);
}
}];
} else {
NSLog(@"Error fetching object: %@", error);
}
}]; }
现在我需要能够将图片上传到此ID。我怎么做?我有选择图像的所有代码。在此先感谢您的帮助。 儒略
答案 0 :(得分:0)
我解决了一点不同。
我这样做了:
-(IBAction)UploadImage:(id)sender {
// Convert to JPEG with 50% quality
NSData* data = UIImageJPEGRepresentation(ImageView.image, 0.5f);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:data];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// The image has now been uploaded to Parse. Associate it with a new object
PFObject* newPhotoObject = [PFObject objectWithClassName:@"PhotoObject"];
[newPhotoObject setObject:imageFile forKey:@"image"];
[newPhotoObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"Saved");
}
else{
// Error
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
}];
}
现在它无缝地工作。