Created
July 29, 2012 01:03
-
-
Save longlongjump/3195553 to your computer and use it in GitHub Desktop.
file uploading
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
NSString *file_path = [[NSBundle mainBundle] pathForResource:@"06 mullet fever" ofType:@"mp3"]; | |
NSURL *url = [NSURL URLWithString:@"http://urbanentourage.com"]; | |
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:url]; | |
NSMutableURLRequest *req = [client multipartFormRequestWithMethod:@"POST" | |
path:@"api/sightings" | |
parameters:[NSDictionary dictionaryWithObject:@"DOU1" forKey:@"sighting[name]"] | |
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
[formData appendPartWithFileData:[NSData dataWithContentsOfFile:file_path] | |
name:@"sighting[sound]" | |
fileName:@"sound.mp3" | |
mimeType:@"audio/mp3"]; | |
}]; | |
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:req]; | |
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSString *str = [[NSString alloc] initWithData:responseObject | |
encoding:NSUTF8StringEncoding]; | |
NSLog(@"%@",str); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
}]; | |
[operation start]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment