|
@@ -440,6 +440,10 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
|
440
|
440
|
@synthesize filePathPrefix;
|
441
|
441
|
@synthesize bridge = _bridge;
|
442
|
442
|
|
|
443
|
+- (dispatch_queue_t) methodQueue {
|
|
444
|
+ return dispatch_queue_create("RNFetchBlob.queue", DISPATCH_QUEUE_SERIAL);
|
|
445
|
+}
|
|
446
|
+
|
443
|
447
|
RCT_EXPORT_MODULE();
|
444
|
448
|
|
445
|
449
|
- (id) init {
|
|
@@ -489,14 +493,14 @@ RCT_EXPORT_METHOD(fetchBlobForm:(NSDictionary *)options
|
489
|
493
|
}
|
490
|
494
|
// field contains a file
|
491
|
495
|
else {
|
492
|
|
- NSMutableData * blobData = [NSMutableData alloc];
|
|
496
|
+ NSMutableData * blobData;
|
493
|
497
|
if(content != nil) {
|
494
|
498
|
if([content hasPrefix:self.filePathPrefix]) {
|
495
|
499
|
NSString * orgPath = [content substringFromIndex:[self.filePathPrefix length]];
|
496
|
|
- [blobData initWithContentsOfFile:orgPath];
|
|
500
|
+ blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
|
497
|
501
|
}
|
498
|
502
|
else
|
499
|
|
- [blobData initWithBase64EncodedString:content options:0];
|
|
503
|
+ blobData = [[NSData alloc] initWithBase64EncodedString:content options:0];
|
500
|
504
|
}
|
501
|
505
|
NSString * filename = [field valueForKey:@"filename"];
|
502
|
506
|
[postData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
|
@@ -543,18 +547,18 @@ RCT_EXPORT_METHOD(fetchBlob:(NSDictionary *)options
|
543
|
547
|
URLWithString: url]];
|
544
|
548
|
|
545
|
549
|
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[FetchBlobUtils normalizeHeaders:headers]];
|
|
550
|
+ // move heavy task to another thread
|
546
|
551
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
547
|
552
|
// if method is POST or PUT, convert data string format
|
548
|
553
|
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
|
549
|
554
|
// generate octet-stream body
|
550
|
555
|
if(body != nil) {
|
551
|
|
- NSMutableData * blobData = [NSData alloc];
|
552
|
|
- // move heavy task to another thread
|
|
556
|
+ NSMutableData * blobData;
|
553
|
557
|
|
554
|
558
|
// when body is a string contains file path prefix, try load file from the path
|
555
|
559
|
if([body hasPrefix:self.filePathPrefix]) {
|
556
|
560
|
NSString * orgPath = [body substringFromIndex:[self.filePathPrefix length]];
|
557
|
|
- [blobData initWithContentsOfFile: orgPath];
|
|
561
|
+ blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
|
558
|
562
|
}
|
559
|
563
|
// otherwise convert it as BASE64 data string
|
560
|
564
|
else
|