我正在尝试将图像从手机上传到服务器。一切正常,除了使用下面的代码使用“头像”作为文件名。所以我想我的问题是,我让他们选择一张照片,或者用相机拍照。我是否知道它将是哪种类型的文件,即 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];
}