@@ -36,12 +36,12 @@ +(void) buildMultipartRequest:(NSDictionary *)options
36
36
37
37
// send request
38
38
__block NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: [NSURL URLWithString: encodedUrl]];
39
- NSMutableDictionary *mheaders = [[NSMutableDictionary alloc ] initWithDictionary: [RNFetchBlobNetwork normalizeHeaders: headers]];
39
+ __block NSMutableDictionary *mheaders = [[NSMutableDictionary alloc ] initWithDictionary: [RNFetchBlobNetwork normalizeHeaders: headers]];
40
40
NSTimeInterval timeStamp = [[NSDate date ] timeIntervalSince1970 ];
41
41
NSNumber * timeStampObj = [NSNumber numberWithDouble: timeStamp];
42
42
43
43
// generate boundary
44
- NSString * boundary = [NSString stringWithFormat: @" RNFetchBlob%d " , timeStampObj];
44
+ __block NSString * boundary = [NSString stringWithFormat: @" RNFetchBlob%d " , timeStampObj];
45
45
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
46
46
__block NSMutableData * postData = [[NSMutableData alloc ] init ];
47
47
// combine multipart/form-data body
@@ -148,7 +148,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
148
148
149
149
+(void ) buildFormBody : (NSArray *)form boundary : (NSString *)boundary onComplete : (void (^)(NSData * formData))onComplete
150
150
{
151
- NSMutableData * formData = [[NSMutableData alloc ] init ];
151
+ __block NSMutableData * formData = [[NSMutableData alloc ] init ];
152
152
if (form == nil )
153
153
onComplete (nil );
154
154
else
@@ -159,7 +159,7 @@ +(void) buildFormBody:(NSArray *)form boundary:(NSString *)boundary onComplete:(
159
159
void __block (^getFieldData)(id field) = ^(id field)
160
160
{
161
161
NSString * name = [field valueForKey: @" name" ];
162
- NSString * content = [field valueForKey: @" data" ];
162
+ __block NSString * content = [field valueForKey: @" data" ];
163
163
NSString * contentType = [field valueForKey: @" type" ];
164
164
// skip when the form field `name` or `data` is empty
165
165
if (content == nil || name == nil )
@@ -197,10 +197,14 @@ void __block (^getFieldData)(id field) = ^(id field)
197
197
i++;
198
198
if (i < count)
199
199
{
200
- getFieldData ([form objectAtIndex: i]);
200
+ __block NSDictionary * nextField = [form objectAtIndex: i];
201
+ getFieldData (nextField);
201
202
}
202
203
else
204
+ {
203
205
onComplete (formData);
206
+ getFieldData = nil ;
207
+ }
204
208
}];
205
209
return ;
206
210
}
@@ -213,17 +217,23 @@ void __block (^getFieldData)(id field) = ^(id field)
213
217
[formData appendData: [[NSString stringWithFormat: @" Content-Type: %@ \r\n\r\n " , contentType] dataUsingEncoding: NSUTF8StringEncoding]];
214
218
[formData appendData: blobData];
215
219
[formData appendData: [[NSString stringWithFormat: @" \r\n " ] dataUsingEncoding: NSUTF8StringEncoding]];
220
+ blobData = nil ;
216
221
}
217
222
i++;
218
223
if (i < count)
219
224
{
220
- getFieldData ([form objectAtIndex: i]);
225
+ __block NSDictionary * nextField = [form objectAtIndex: i];
226
+ getFieldData (nextField);
221
227
}
222
228
else
229
+ {
223
230
onComplete (formData);
231
+ getFieldData = nil ;
232
+ }
224
233
225
234
};
226
- getFieldData ([form objectAtIndex: i]);
235
+ __block NSDictionary * nextField = [form objectAtIndex: i];
236
+ getFieldData (nextField);
227
237
}
228
238
}
229
239
0 commit comments