I have a procedure that sends image taken through my iPad app to a database (code below). Is there a way of reducing the size of the image before it is posted?
UIImage *image = [photos objectAtIndex:i];
NSData *imageData = UIImageJPEGRepresentation(image, 10);
// setting up the request object
NSMutableURLRequest *photoRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:photoPostString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[photoRequest setHTTPMethod:@"POST"];
NSMutableURLRequest *photoRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:photoPostString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[photoRequest setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
photoRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"1234.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:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[photoRequest setHTTPBody:body];