Skip to content

Instantly share code, notes, and snippets.

@mattt
Created May 14, 2014 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattt/2fa6d0f5e544b54952d7 to your computer and use it in GitHub Desktop.
Save mattt/2fa6d0f5e544b54952d7 to your computer and use it in GitHub Desktop.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"Pa55w0rd"]
NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
[manager POST:@"http://example.com/resources.json" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:filePath name:@"image" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment