First, you can get an NSData object containing a PNG or JPEG representation of the image data using the functions UIImagePNGRepresentation and UIImageJPEGRepresentation.
(see the UIImage class reference for more information)
To complete the download of data from your iPhone to your server, you can do this:
- (void)sendImage { NSData *postData = [nsdata from your original image]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; // Init and set fields of the URLRequest NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setHTTPMethod:@"POST"]; [request setURL:[NSURL URLWithString:[NSString stringWithString:@"http://yoururl.domain"]]]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (connection) { // Return data of the request NSData *receivedData = [[NSMutableData data] retain]; } [request release]; }
source share