I’m trying to upload an image from the phone to the server. Everything is working fine, except using the code below it’s using “Avatar” as the file name. So I guess my question is, I’m giving them the choice to choose a picture, or take a picture with the camera. Do I know which type of file it will be i.e. png, jpg or do I need to figure that out before I upload it?
- (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];
}
This line is your answer:
You are creating a PNG image.