@@ -28,7 +28,7 @@ +(void) buildMultipartRequest:(NSDictionary *)options
2828 url : (NSString *)url
2929 headers : (NSDictionary *)headers
3030 form : (NSArray *)form
31- onComplete : (void (^)(NSURLRequest * req))onComplete
31+ onComplete : (void (^)(NSURLRequest * req, long bodyLength ))onComplete
3232{
3333 NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
3434 // send request
@@ -56,7 +56,7 @@ +(void) buildMultipartRequest:(NSDictionary *)options
5656 [mheaders setValue: [NSString stringWithFormat: @" multipart/form-data; charset=utf-8; boundary=%@ " , boundary] forKey: @" content-type" ];
5757 [request setHTTPMethod: method];
5858 [request setAllHTTPHeaderFields: mheaders];
59- onComplete (request);
59+ onComplete (request, [formData length ] );
6060 }];
6161
6262 });
@@ -69,7 +69,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
6969 url : (NSString *)url
7070 headers : (NSDictionary *)headers
7171 body : (NSString *)body
72- onComplete : (void (^)(NSURLRequest * req))onComplete
72+ onComplete : (void (^)(NSURLRequest * req, long bodyLength ))onComplete
7373{
7474 NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
7575 // send request
@@ -81,6 +81,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
8181 // move heavy task to another thread
8282 dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
8383 NSMutableData * blobData;
84+ long size = -1 ;
8485 // if method is POST or PUT, convert data string format
8586 if ([[method lowercaseString ] isEqualToString: @" post" ] || [[method lowercaseString ] isEqualToString: @" put" ]) {
8687 // generate octet-stream body
@@ -97,10 +98,11 @@ +(void) buildOctetRequest:(NSDictionary *)options
9798 [mheaders setValue: @" application/octet-stream" forKey: @" content-type" ];
9899 [request setHTTPMethod: method];
99100 [request setAllHTTPHeaderFields: mheaders];
100- onComplete (request);
101+ onComplete (request, [content length ] );
101102 }];
102103 return ;
103104 }
105+ size = [[[NSFileManager defaultManager ] attributesOfItemAtPath: orgPath error: nil ] fileSize ];
104106 [request setHTTPBodyStream: [NSInputStream inputStreamWithFileAtPath: orgPath ]];
105107 }
106108 // otherwise convert it as BASE64 data string
@@ -117,7 +119,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
117119 [request setHTTPMethod: method];
118120 [request setAllHTTPHeaderFields: mheaders];
119121
120- onComplete (request);
122+ onComplete (request, size );
121123 });
122124}
123125
@@ -135,6 +137,7 @@ void __block (^getFieldData)(id field) = ^(id field)
135137 NSString * name = [field valueForKey: @" name" ];
136138 NSString * content = [field valueForKey: @" data" ];
137139 NSString * contentType = [field valueForKey: @" type" ];
140+ contentType = contentType == nil ? @" application/octet-stream" : contentType;
138141 // field is a text field
139142 if ([field valueForKey: @" filename" ] == nil || content == [NSNull null ]) {
140143 [formData appendData: [[NSString stringWithFormat: @" --%@ \r\n " , boundary] dataUsingEncoding: NSUTF8StringEncoding]];
0 commit comments