Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
[Issue #554] Re-adding AFMultipartFormData -appendPartWithHeaders:body:
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Oct 3, 2012
1 parent 9cdea00 commit f9c0576
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
9 changes: 9 additions & 0 deletions AFNetworking/AFHTTPClient.h
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -819,13 +819,7 @@ - (void)appendPartWithFileData:(NSData *)data
[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
Expand All @@ -834,11 +828,17 @@ - (void)appendPartWithFormData:(NSData *)data
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];
}
Expand Down

0 comments on commit f9c0576

Please sign in to comment.