Skip to content

Instantly share code, notes, and snippets.

@longlongjump
Created July 29, 2012 01:03
Show Gist options
  • Save longlongjump/3195553 to your computer and use it in GitHub Desktop.
Save longlongjump/3195553 to your computer and use it in GitHub Desktop.
file uploading
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