NSData *imageData = UIImagePNGRepresentation(image);
POSTを使用してimageDataを送信する方法は?
次のコードが役立ちます
NSData *imageData = UIImagePNGRepresentation(image);
NSURL *yourURL = ...
NSMutableURLRequest *yourRequest = [NSMutableURLRequest requestWithURL:yourURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
//Set request to post
[yourRequest setHTTPMethod:@"POST"];
//Set content type
[yourRequest setValue:@"image/png" forHTTPHeaderField:@"Content-Type"];
// Set authorization header if required
...
// set data
[yourRequest setHTTPBody:imageData];
// create connection and set delegate if needed
NSURLConnection *yourConnection = [[NSURLConnection alloc] initWithRequest:yourRequest
delegate:self
startImmediately:YES];
ARC を使用していることを前提としていることにご注意ください。
NSURLConnection https://stackoverflow.com/a/10750428/591951を使用しても問題ない場合は、この回答を確認できます
この投稿では、オーディオ ファイルを POST する方法について説明しますが、同じ方法を使用して任意のファイルをアップロードできます。
ASIHTTPRequest ライブラリを使用できます: http://allseeing-i.com/ASIHTTPRequest/
次に、それは非常に簡単です:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
// Upload an NSData instance
[request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
使用方法に関する情報: http://allseeing-i.com/ASIHTTPRequest/How-to-use