My application allows the user to take a picture in the camera/or choose from his photo library.
I would like the posted image to be in resolution 650X550
However I see:
After this code the size is 320X480
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
chosenImage = image;
NSLog(@"The widht is %f",image.size.width);
NSLog(@"The height is %f",image.size.height);
}
When I submit the image like this – I retrieve it in 1024X480 on the server side
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://myurl/upload/"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSData *imageData = UIImageJPEGRepresentation(appDelegate.chosenImage, 0.5);
// file
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"file\"; filename=\"iphone.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// set request body
[request setHTTPBody:body];
I would like to retrieve it as 650X550 – the size that I declared in objcetive-c – to my code on server side
When I try to submit to my backend code with a regular HTML page – it sends the original size of the image and not 1024X480.
How can I achieve retrieving an image in its original size?
you have no influence on the size you get from the picker — though it should be MUCH larger
you can manually scale it before the upload
DEMO:
objc-side: