Created
July 23, 2012 03:26
-
-
Save tatsuro-ueda/3161878 to your computer and use it in GitHub Desktop.
Objectice-Cでファイルをアップロードする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)upload:(id)sender { | |
NSURL *url = [NSURL URLWithString:@"http://192.168.100.203:4567/"]; | |
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; | |
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:_filePath.lastPathComponent], 0.5); | |
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { | |
[formData appendPartWithFileData:imageData name:@"file" fileName:_filePath.lastPathComponent mimeType:@"image/jpeg"]; | |
}]; | |
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; | |
// [operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { | |
// NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite); | |
// }]; | |
[operation start]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment