1

How can I upload an image from the library or camera using ASIHTTP?

NSString *post;
self.view.userInteractionEnabled = FALSE;
post = [NSString stringWithFormat:@"    "];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *urlString1 = [NSString stringWithFormat:/* [...] */];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *myWebserverURL = [NSURL URLWithString:urlString1]; 
NSMutableURLRequest *request1 = [[[NSMutableURLRequest alloc] init] autorelease];

[request1 setURL:myWebserverURL];
[request1 setHTTPMethod:@"POST"];
[request1 setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request1 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request1 setHTTPBody:postData];

connectionFlag = FALSE; 

conn = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];


if (conn){
    receivedData = [[NSMutableData data] retain];

} else {
    isValidation = FALSE;
    NSLog(@"no data retrieved");
}   

This what i had done for text fields

Emil
  • 7,220
  • 17
  • 76
  • 135
fayaz
  • 91
  • 1
  • 1
  • 6
  • you must use the multipart mime type http://stackoverflow.com/questions/8042360/nsdata-and-uploading-images-via-post-in-ios – iArezki May 26 '12 at 09:12

0 Answers0