Last active
August 29, 2015 14:05
-
-
Save fahied/07cb50d906a904f23f8b to your computer and use it in GitHub Desktop.
Multipart-formdata PUT using AFNetworking
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
+(void)putMultipartWhereRoute:(NSString*)route jsonData:(NSData*)jsonData images:(NSArray*)images completion:(void (^)(NSError *error, NSDictionary *response))completion | |
{ | |
NetworkManager *networkManger = [NetworkManager sharedManager]; | |
NSString *serviceURL = [[networkManger.baseURL absoluteString] stringByAppendingString:route]; | |
NSMutableURLRequest *request = [networkManger.requestSerializer multipartFormRequestWithMethod:@"PUT" URLString:serviceURL parameters:nil constructingBodyWithBlock:^(id formData) { | |
//append json data | |
[formData appendPartWithFormData:jsonData name:@"note"]; | |
//append images | |
int i = 0; | |
for (NSString *imageRef in images) { | |
NSURL *imagePath = [NSURL fileURLWithPath:imageRef]; | |
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imagePath]]; | |
NSLog(@"image%@",[image description]); | |
[formData appendPartWithFileURL:imagePath name:[NSString stringWithFormat:@"image%d",i] error:nil]; | |
i++; | |
} | |
} error: nil]; | |
NSURLSessionDataTask *dataTask = [networkManger dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { | |
NSLog(@"response : %@",responseObject); | |
completion(nil, responseObject); | |
}]; | |
[dataTask resume]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment