I'm uploading images (jpg) to .net service. If I upload small images the upload works great, but when I send "big" images (more than 1 Mb or "big" size) images upload success, but the image looks like this
I tested web service via curl and it works ok.
Any Idea? Thanks you!!!!!!
My upload code is:
-(void)uploadJPEGImage:(NSString*)requestURL image:(UIImage*)image pictureName: (NSString*)pictureName {
NSURL *url = [[NSURL alloc] initWithString:requestURL];
NSMutableURLRequest *urequest = [NSMutableURLRequest requestWithURL:url];
[urequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[urequest setHTTPShouldHandleCookies:NO];
[urequest setTimeoutInterval:600];
NSData *postImageData = UIImageJPEGRepresentation(image, 0.9 );
NSMutableData *body = [NSMutableData data];
[urequest setHTTPMethod:@"POST"];
//STEP2 Creating Boundary
// There are no rules as of the content of the boundary but as it must not occur in any of the parts of your message content is usually a randomly generated sequence of numbers, letters or combination of both in order to guarantee uniqueness and differentiate from any possible dictionary words.
NSString *boundary = @"---------------------------14737809831466499882746641449";
//Setting POST Header
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[urequest addValue:contentType forHTTPHeaderField:@"Content-Type"];
//STEP3 Begin boundary
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//STEP4 Adding additional parameters
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n",pictureName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//STEP5 Appending Image Data
[body appendData:[NSData dataWithData:postImageData]];
//STEP6 Closing boundary
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[urequest setHTTPBody:body];
//Set content length
NSString* postlength = [NSString stringWithFormat:@"%d", [body length]];
[urequest setValue:postlength forHTTPHeaderField:@"Content-Length"];
[url release];
NSURLConnection *conaux =[[NSURLConnection alloc] initWithRequest:urequest delegate:self startImmediately:NO];
self.connection = conaux;
[conaux release];
NSMutableData *auxdata = [[NSMutableData alloc] init];
self.receivedData = auxdata;
[auxdata release];
}