file data upload fix
This commit is contained in:
parent
cf0f82a74d
commit
4f070b2924
2 changed files with 20 additions and 11 deletions
|
|
@ -37,7 +37,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The url used as the base for paths specified in methods such as `getPath:parameters:success:failure`
|
The url used as the base for paths specified in methods such as `getPath:parameteres:success:failure`
|
||||||
*/
|
*/
|
||||||
@property (readonly, nonatomic, retain) NSURL *baseURL;
|
@property (readonly, nonatomic, retain) NSURL *baseURL;
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
/**
|
/**
|
||||||
The operation queue which manages operations enqueued by the HTTP client.
|
The operation queue which manages operations enqueued by the HTTP client.
|
||||||
*/
|
*/
|
||||||
@property (readonly, nonatomic, retain) NSOperationQueue *operationQueue;
|
@property (readonly, nonatomic, retain) NSOperationQueue *operationQueue;;
|
||||||
|
|
||||||
///---------------------------------------------
|
///---------------------------------------------
|
||||||
/// @name Creating and Initializing HTTP Clients
|
/// @name Creating and Initializing HTTP Clients
|
||||||
|
|
@ -267,6 +267,8 @@
|
||||||
*/
|
*/
|
||||||
- (void)appendPartWithFile:(NSURL *)fileURL mimeType:(NSString *)mimeType fileName:(NSString *)fileName;
|
- (void)appendPartWithFile:(NSURL *)fileURL mimeType:(NSString *)mimeType fileName:(NSString *)fileName;
|
||||||
|
|
||||||
|
- (void)appendPartWithFileData:(NSData *)data mimeType:(NSString *)mimeType name:(NSString *)name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends encoded data to the form data.
|
Appends encoded data to the form data.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF
|
||||||
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
|
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
|
||||||
|
|
||||||
static NSString * AFMultipartFormEncapsulationBoundary() {
|
static NSString * AFMultipartFormEncapsulationBoundary() {
|
||||||
return [NSString stringWithFormat:@"--%@", kAFMultipartFormBoundary];
|
return [NSString stringWithFormat:@"%@--%@%@", kAFMultipartFormLineDelimiter, kAFMultipartFormBoundary, kAFMultipartFormLineDelimiter];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString * AFMultipartFormFinalBoundary() {
|
static NSString * AFMultipartFormFinalBoundary() {
|
||||||
return [NSString stringWithFormat:@"--%@--", kAFMultipartFormBoundary];
|
return [NSString stringWithFormat:@"%@--%@--", kAFMultipartFormLineDelimiter, kAFMultipartFormBoundary];
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface AFMultipartFormDataProxy : NSObject <AFMultipartFormDataProxy> {
|
@interface AFMultipartFormDataProxy : NSObject <AFMultipartFormDataProxy> {
|
||||||
|
|
@ -305,21 +305,17 @@ static NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSS
|
||||||
- (NSData *)data {
|
- (NSData *)data {
|
||||||
NSMutableData *finalizedData = [NSMutableData dataWithData:self.mutableData];
|
NSMutableData *finalizedData = [NSMutableData dataWithData:self.mutableData];
|
||||||
[finalizedData appendData:[AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding]];
|
[finalizedData appendData:[AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding]];
|
||||||
|
|
||||||
return finalizedData;
|
return finalizedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - AFMultipartFormDataProxy
|
#pragma mark - AFMultipartFormDataProxy
|
||||||
|
|
||||||
- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body {
|
- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body {
|
||||||
if ([self.mutableData length] > 0) {
|
|
||||||
[self appendString:AFMultipartFormEncapsulationBoundary()];
|
[self appendString:AFMultipartFormEncapsulationBoundary()];
|
||||||
[self appendBlankLine];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (NSString *field in [headers allKeys]) {
|
for (NSString *field in [headers allKeys]) {
|
||||||
[self appendString:[NSString stringWithFormat:@"%@: %@", field, [headers valueForKey:field]]];
|
[self appendString:[NSString stringWithFormat:@"%@: %@%@", field, [headers valueForKey:field], kAFMultipartFormLineDelimiter]];
|
||||||
[self appendBlankLine];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self appendBlankLine];
|
[self appendBlankLine];
|
||||||
|
|
@ -351,6 +347,17 @@ static NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSS
|
||||||
[self appendPartWithHeaders:mutableHeaders body:data];
|
[self appendPartWithHeaders:mutableHeaders body:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)appendPartWithFileData:(NSData *)data mimeType:(NSString *)mimeType name:(NSString *)name {
|
||||||
|
|
||||||
|
NSString *fileName = [[NSString stringWithFormat:@"%d", [[NSDate date] hash]] stringByAppendingPathExtension:[mimeType lastPathComponent]];
|
||||||
|
|
||||||
|
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
|
||||||
|
[mutableHeaders setValue:[NSString stringWithFormat:@"file; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
|
||||||
|
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
|
||||||
|
|
||||||
|
[self appendPartWithHeaders:mutableHeaders body:data];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)appendData:(NSData *)data {
|
- (void)appendData:(NSData *)data {
|
||||||
[self.mutableData appendData:data];
|
[self.mutableData appendData:data];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue