gpt4 book ai didi

ios - 如何通过 iOS 中的 JSON webservices post 方法将一组图像发送到服务器?

转载 作者:行者123 更新时间:2023-11-29 12:39:59 25 4
gpt4 key购买 nike

我想知道如何使用 UIImagePickerController 获取一组图像,并将一个数组发布到服务器,以及如何使用 JSON Web 服务从服务器获取一组图像。而且我还需要将图像信息(拍摄日期)发布到服务器。

我正在使用 UIImagePickerController 获取图像。这是我的代码

-(IBAction)fileselectionAction:(id)sender{

[self.view endEditing:YES];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Pick Photo From" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Photo Album", @"Take New Photo", @"Cancel", nil];

[actionSheet showFromToolbar:self.navigationController.toolbar];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;

if (buttonIndex == 0) {
//[self.imagePickerController setAllowsEditing:YES];
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = YES;
[self presentViewController:self.imagePickerController animated:YES completion:nil];

} else if (buttonIndex == 1) {

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.imagePickerController setAllowsEditing:YES];
//self.imagePickerController.showsCameraControls = YES;

[self presentViewController:self.imagePickerController animated:YES completion:nil];

}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)info
{

[picker dismissViewControllerAnimated:YES completion:nil];
picker = nil;
NSData *imageData = UIImageJPEGRepresentation(image,0.0);
self.image1 = [UIImage imageWithData:imageData];
}

提前致谢。

最佳答案

Web 服务不提供用于发送图像的 API 吗?如果是这样,请使用它。

否则,如果您也自己开发网络服务,请不要使用 JSON 嵌入图像,而是使用适当的内容类型。

如果您绝对必须使用 JSON,则需要将图像编码为 JSON 兼容的字符串,例如base64,然后将带有元数据的图像作为 JSON 字符串发送。

关于ios - 如何通过 iOS 中的 JSON webservices post 方法将一组图像发送到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236826/

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