|
@@ -28,7 +28,7 @@
|
28
|
28
|
url:(NSString *)url
|
29
|
29
|
headers:(NSDictionary *)headers
|
30
|
30
|
form:(NSArray *)form
|
31
|
|
- onComplete:(void(^)(NSURLRequest * req))onComplete
|
|
31
|
+ onComplete:(void(^)(NSURLRequest * req, long bodyLength))onComplete
|
32
|
32
|
{
|
33
|
33
|
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
34
|
34
|
// send request
|
|
@@ -56,7 +56,7 @@
|
56
|
56
|
[mheaders setValue:[NSString stringWithFormat:@"multipart/form-data; charset=utf-8; boundary=%@", boundary] forKey:@"content-type"];
|
57
|
57
|
[request setHTTPMethod: method];
|
58
|
58
|
[request setAllHTTPHeaderFields:mheaders];
|
59
|
|
- onComplete(request);
|
|
59
|
+ onComplete(request, [formData length]);
|
60
|
60
|
}];
|
61
|
61
|
|
62
|
62
|
});
|
|
@@ -69,7 +69,7 @@
|
69
|
69
|
url:(NSString *)url
|
70
|
70
|
headers:(NSDictionary *)headers
|
71
|
71
|
body:(NSString *)body
|
72
|
|
- onComplete:(void(^)(NSURLRequest * req))onComplete
|
|
72
|
+ onComplete:(void(^)(NSURLRequest * req, long bodyLength))onComplete
|
73
|
73
|
{
|
74
|
74
|
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
75
|
75
|
// send request
|
|
@@ -81,6 +81,7 @@
|
81
|
81
|
// move heavy task to another thread
|
82
|
82
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
83
|
83
|
NSMutableData * blobData;
|
|
84
|
+ long size = -1;
|
84
|
85
|
// if method is POST or PUT, convert data string format
|
85
|
86
|
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
|
86
|
87
|
// generate octet-stream body
|
|
@@ -97,10 +98,11 @@
|
97
|
98
|
[mheaders setValue:@"application/octet-stream" forKey:@"content-type"];
|
98
|
99
|
[request setHTTPMethod: method];
|
99
|
100
|
[request setAllHTTPHeaderFields:mheaders];
|
100
|
|
- onComplete(request);
|
|
101
|
+ onComplete(request, [content length]);
|
101
|
102
|
}];
|
102
|
103
|
return;
|
103
|
104
|
}
|
|
105
|
+ size = [[[NSFileManager defaultManager] attributesOfItemAtPath:orgPath error:nil] fileSize];
|
104
|
106
|
[request setHTTPBodyStream: [NSInputStream inputStreamWithFileAtPath:orgPath ]];
|
105
|
107
|
}
|
106
|
108
|
// otherwise convert it as BASE64 data string
|
|
@@ -117,7 +119,7 @@
|
117
|
119
|
[request setHTTPMethod: method];
|
118
|
120
|
[request setAllHTTPHeaderFields:mheaders];
|
119
|
121
|
|
120
|
|
- onComplete(request);
|
|
122
|
+ onComplete(request, size);
|
121
|
123
|
});
|
122
|
124
|
}
|
123
|
125
|
|
|
@@ -135,6 +137,7 @@
|
135
|
137
|
NSString * name = [field valueForKey:@"name"];
|
136
|
138
|
NSString * content = [field valueForKey:@"data"];
|
137
|
139
|
NSString * contentType = [field valueForKey:@"type"];
|
|
140
|
+ contentType = contentType == nil ? @"application/octet-stream" : contentType;
|
138
|
141
|
// field is a text field
|
139
|
142
|
if([field valueForKey:@"filename"] == nil || content == [NSNull null]) {
|
140
|
143
|
[formData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|