gpt4 book ai didi

ios - 尝试在 iOS 应用程序中保存带有图像的解析对象

转载 作者:行者123 更新时间:2023-11-29 02:17:31 24 4
gpt4 key购买 nike

在 View Controller 中,用户可以从照片库中选择一张图片,添加文本,然后在按下按钮后,应用程序应创建一个 PFObject 并将其保存在后台。这是我的按钮操作代码方法:

-(IBAction)sendPressed:(id)sender
{


NSLog(@"boton subir cadena pulsado");

//Upload a new picture
NSData *pictureData = UIImagePNGRepresentation(self.imageView.image);

PFFile *file = [PFFile fileWithName:@"img" data:pictureData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

if (succeeded){
NSLog(@"IMAGEN CARGADA");

//Add the image to the object, and add the comments
PFObject *imageObject = [PFObject objectWithClassName:@"cadenas"];
[imageObject setObject:file forKey:@"image"];

[imageObject setObject:self.commentTextField.text forKey:@"chain_name"];


[imageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

if (succeeded){
//Go back to the wall
[self.navigationController popViewControllerAnimated:YES];
}
else{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
[self showErrorView:errorString];
}
}];
}
else{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
[self showErrorView:errorString];
}



} progressBlock:^(int percentDone) {

}];
}

一段时间后,调试器出现错误:Error: invalid type for key image, expected map, but got file (Code: 111, Version: 1.2.15)

我一直在 Parse 文档中搜索,但对这个问题一无所知。

最佳答案

您一定是为您的列选择了错误的类型。将其更改为文件类型。

            NSData *imageData = UIImagePNGRepresentation(YourImageView.image);

PFFile *imageFile = [PFFile fileWithData:imageData];
[userObject setObject:imageFile forKey:@"YOUR_KEY"];
[userObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(succeeded)
{
NSLog(@"Object saved");
}else
{
NSLog(@"Error : %@",error);
}
}];

关于ios - 尝试在 iOS 应用程序中保存带有图像的解析对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28576643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com