diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 93abec6..6a79ebb 100755 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -547,6 +547,15 @@ extern NSUInteger const kAFUploadStream3GSuggestedDelay; - (void)appendPartWithFormData:(NSData *)data name:(NSString *)name; +/** + Appends HTTP headers, followed by the encoded data and the multipart form boundary. + + @param headers The HTTP headers to be appended to the form data. + @param body The data to be encoded and appended to the form data. + */ +- (void)appendPartWithHeaders:(NSDictionary *)headers + body:(NSData *)body; + /** Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream. diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 56d8485..f8ef067 100755 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -819,13 +819,7 @@ NSUInteger const kAFUploadStream3GSuggestedDelay = 0.2; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"]; [mutableHeaders setValue:mimeType forKey:@"Content-Type"]; - AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init]; - bodyPart.stringEncoding = self.stringEncoding; - bodyPart.headers = mutableHeaders; - bodyPart.bodyContentLength = [data length]; - bodyPart.inputStream = [NSInputStream inputStreamWithData:data]; - - [self.bodyStream appendHTTPBodyPart:bodyPart]; + [self appendPartWithHeaders:mutableHeaders body:data]; } - (void)appendPartWithFormData:(NSData *)data @@ -834,11 +828,17 @@ NSUInteger const kAFUploadStream3GSuggestedDelay = 0.2; NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary]; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"]; + [self appendPartWithHeaders:mutableHeaders body:data]; +} + +- (void)appendPartWithHeaders:(NSDictionary *)headers + body:(NSData *)body +{ AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init]; bodyPart.stringEncoding = self.stringEncoding; - bodyPart.headers = mutableHeaders; - bodyPart.bodyContentLength = [data length]; - bodyPart.inputStream = [NSInputStream inputStreamWithData:data]; + bodyPart.headers = headers; + bodyPart.bodyContentLength = [body length]; + bodyPart.inputStream = [NSInputStream inputStreamWithData:body]; [self.bodyStream appendHTTPBodyPart:bodyPart]; }