Merge pull request #860 from Picturelife/master
Add ability to append a part with an NSInputStream to AFMultipartFormData protocol
This commit is contained in:
commit
17b244f86e
2 changed files with 43 additions and 0 deletions
|
|
@ -597,6 +597,7 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay;
|
||||||
- (void)appendPartWithFormData:(NSData *)data
|
- (void)appendPartWithFormData:(NSData *)data
|
||||||
name:(NSString *)name;
|
name:(NSString *)name;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends HTTP headers, followed by the encoded data and the multipart form boundary.
|
Appends HTTP headers, followed by the encoded data and the multipart form boundary.
|
||||||
|
|
||||||
|
|
@ -606,6 +607,21 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay;
|
||||||
- (void)appendPartWithHeaders:(NSDictionary *)headers
|
- (void)appendPartWithHeaders:(NSDictionary *)headers
|
||||||
body:(NSData *)body;
|
body:(NSData *)body;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the data from the input stream and the multipart form boundary.
|
||||||
|
|
||||||
|
@param inputStream The input stream to be appended to the form data
|
||||||
|
@param name The name to be associated with the specified input stream. This parameter must not be `nil`.
|
||||||
|
@param fileName The filename to be associated with the specified input stream. This parameter must not be `nil`.
|
||||||
|
@param length The length of the specified input stream in bytes.
|
||||||
|
@param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
|
||||||
|
*/
|
||||||
|
- (void)appendPartWithInputStream:(NSInputStream *)inputStream
|
||||||
|
name:(NSString *)name
|
||||||
|
fileName:(NSString *)fileName
|
||||||
|
length:(unsigned long long)length
|
||||||
|
mimeType:(NSString *)mimeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream.
|
Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -916,6 +916,31 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
|
||||||
[self.bodyStream appendHTTPBodyPart:bodyPart];
|
[self.bodyStream appendHTTPBodyPart:bodyPart];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)appendPartWithInputStream:(NSInputStream *)inputStream
|
||||||
|
name:(NSString *)name
|
||||||
|
fileName:(NSString *)fileName
|
||||||
|
length:(unsigned long long)length
|
||||||
|
mimeType:(NSString *)mimeType
|
||||||
|
{
|
||||||
|
NSParameterAssert(name);
|
||||||
|
NSParameterAssert(fileName);
|
||||||
|
NSParameterAssert(mimeType);
|
||||||
|
|
||||||
|
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||||
|
[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.body = inputStream;
|
||||||
|
|
||||||
|
bodyPart.bodyContentLength = length;
|
||||||
|
|
||||||
|
[self.bodyStream appendHTTPBodyPart:bodyPart];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
|
- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
|
||||||
delay:(NSTimeInterval)delay
|
delay:(NSTimeInterval)delay
|
||||||
{
|
{
|
||||||
|
|
@ -1174,6 +1199,8 @@ typedef enum {
|
||||||
_inputStream = [NSInputStream inputStreamWithData:self.body];
|
_inputStream = [NSInputStream inputStreamWithData:self.body];
|
||||||
} else if ([self.body isKindOfClass:[NSURL class]]) {
|
} else if ([self.body isKindOfClass:[NSURL class]]) {
|
||||||
_inputStream = [NSInputStream inputStreamWithURL:self.body];
|
_inputStream = [NSInputStream inputStreamWithURL:self.body];
|
||||||
|
} else if ( [self.body isKindOfClass:[NSInputStream class]] ) {
|
||||||
|
_inputStream = self.body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue