[Issue #554] Re-adding AFMultipartFormData -appendPartWithHeaders:body:

This commit is contained in:
Mattt Thompson 2012-10-03 08:37:25 -07:00
parent 9cdea00b07
commit f9c0576f89
2 changed files with 19 additions and 10 deletions

View file

@ -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.

View file

@ -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];
}