gpt4 book ai didi

iOS:如何使用Restkit设置上传到服务器的图像的名称

转载 作者:行者123 更新时间:2023-11-29 04:32:14 26 4
gpt4 key购买 nike

我正在尝试将图像从手机上传到服务器。一切工作正常,除了使用下面的代码使用“阿凡达”作为文件名。所以我想我的问题是,我让他们选择选择一张照片,或者用相机拍照。我是否知道它将是什么类型的文件,即 png、jpg,或者我需要在上传之前弄清楚它吗?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

//self.avatarImage = [[UIImageView alloc] init];
self.avatarImage.image = image;
[self dismissModalViewControllerAnimated:YES];

RKParams* params = [RKParams params];

NSData* imageData = UIImagePNGRepresentation(image);
[params setData:imageData MIMEType:@"image/png" forParam:@"Avatar"];

NSLog(@"RKParams HTTPHeaderValueForContentType = %@", [params HTTPHeaderValueForContentType]);
NSLog(@"RKParams HTTPHeaderValueForContentLength = %d", [params HTTPHeaderValueForContentLength]);

[[RKClient sharedClient] post:@"/user/updateavatar" params:params delegate:self];
}

最佳答案

这一行就是你的答案:

NSData* imageData = UIImagePNGRepresentation(image);

您正在创建 PNG 图像。

关于iOS:如何使用Restkit设置上传到服务器的图像的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11573118/

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