Skip to content

Commit 70fcb28

Browse files
committed
Merge branch '0.5.2'
2 parents 757afca + 868c1d6 commit 70fcb28

File tree

12 files changed

+380
-250
lines changed

12 files changed

+380
-250
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+5-19
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,10 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
160160
RNFetchBlobConfig config = new RNFetchBlobConfig(options);
161161

162162
try {
163-
Uri uri = Uri.parse(url);
164163
AsyncHttpClient req = new AsyncHttpClient();
165164

166-
// set params
167-
RequestParams params = new RequestParams();
168165
AbstractHttpEntity entity = null;
169166

170-
// set params
171-
for (String paramName : uri.getQueryParameterNames()) {
172-
params.put(paramName, uri.getQueryParameter(paramName));
173-
}
174-
175167
// set headers
176168
ReadableMapKeySetIterator it = headers.keySetIterator();
177169
while (it.hasNextKey()) {
@@ -212,7 +204,7 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
212204
// send request
213205
switch(method.toLowerCase()) {
214206
case "get" :
215-
req.get(url, params, handler);
207+
req.get(url, handler);
216208
break;
217209
case "post" :
218210
req.post(this.getReactApplicationContext(), url, entity, "octet-stream", handler);
@@ -221,7 +213,7 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
221213
req.put(this.getReactApplicationContext(), url, entity, "octet-stream",handler);
222214
break;
223215
case "delete" :
224-
req.delete(url, params, handler);
216+
req.delete(url, handler);
225217
break;
226218
}
227219
} catch(Exception error) {
@@ -235,16 +227,10 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
235227

236228
RNFetchBlobConfig config = new RNFetchBlobConfig(options);
237229
try {
238-
Uri uri = Uri.parse(url);
230+
239231
AsyncHttpClient req = new AsyncHttpClient();
240232

241-
// set params
242-
RequestParams params = new RequestParams();
243233
HttpEntity entity = null;
244-
// set params
245-
for (String paramName : uri.getQueryParameterNames()) {
246-
params.put(paramName, uri.getQueryParameter(paramName));
247-
}
248234

249235
// set headers
250236
if(headers != null) {
@@ -307,7 +293,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
307293
// send request
308294
switch(method.toLowerCase()) {
309295
case "get" :
310-
req.get(url, params, handler);
296+
req.get(url, handler);
311297
break;
312298
case "post" :
313299
req.post(this.getReactApplicationContext(), url, entity, "multipart/form-data; charset=utf8", handler);
@@ -316,7 +302,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
316302
req.put(this.getReactApplicationContext(), url, entity, "multipart/form-data",handler);
317303
break;
318304
case "delete" :
319-
req.delete(url, params, handler);
305+
req.delete(url, handler);
320306
break;
321307
}
322308
} catch(Exception error) {

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ function fetch(...args:any):Promise {
104104
let options = this || {}
105105

106106
let promise = new Promise((resolve, reject) => {
107-
108107
let [method, url, headers, body] = [...args]
109108
let nativeMethodName = Array.isArray(body) ? 'fetchBlobForm' : 'fetchBlob'
110109

src/ios/RNFetchBlob.xcodeproj/project.pbxproj

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */; };
1111
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */; };
12-
A158F4301D0539DB006FFD38 /* RNFetchBlobResp.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* RNFetchBlobResp.m */; };
12+
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */; };
1313
A15C30141CD25C330074CB35 /* RNFetchBlob.m in Sources */ = {isa = PBXBuildFile; fileRef = A15C30131CD25C330074CB35 /* RNFetchBlob.m */; };
1414
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */ = {isa = PBXBuildFile; fileRef = A15C30111CD25C330074CB35 /* RNFetchBlob.h */; };
1515
/* End PBXBuildFile section */
@@ -31,8 +31,8 @@
3131
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobFS.h; sourceTree = "<group>"; };
3232
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobConst.h; sourceTree = "<group>"; };
3333
A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobConst.m; sourceTree = "<group>"; };
34-
A158F42E1D0539CE006FFD38 /* RNFetchBlobResp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobResp.h; sourceTree = "<group>"; };
35-
A158F42F1D0539DB006FFD38 /* RNFetchBlobResp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobResp.m; sourceTree = "<group>"; };
34+
A158F42E1D0539CE006FFD38 /* RNFetchBlobNetwork.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobNetwork.h; sourceTree = "<group>"; };
35+
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobNetwork.m; sourceTree = "<group>"; };
3636
A15C300E1CD25C330074CB35 /* libRNFetchBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFetchBlob.a; sourceTree = BUILT_PRODUCTS_DIR; };
3737
A15C30111CD25C330074CB35 /* RNFetchBlob.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFetchBlob.h; path = RNFetchBlob/RNFetchBlob.h; sourceTree = "<group>"; };
3838
A15C30131CD25C330074CB35 /* RNFetchBlob.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFetchBlob.m; path = RNFetchBlob/RNFetchBlob.m; sourceTree = "<group>"; };
@@ -59,8 +59,8 @@
5959
A15C30051CD25C330074CB35 = {
6060
isa = PBXGroup;
6161
children = (
62-
A158F42F1D0539DB006FFD38 /* RNFetchBlobResp.m */,
63-
A158F42E1D0539CE006FFD38 /* RNFetchBlobResp.h */,
62+
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
63+
A158F42E1D0539CE006FFD38 /* RNFetchBlobNetwork.h */,
6464
A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */,
6565
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */,
6666
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */,
@@ -139,7 +139,7 @@
139139
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */,
140140
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */,
141141
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */,
142-
A158F4301D0539DB006FFD38 /* RNFetchBlobResp.m in Sources */,
142+
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */,
143143
A15C30141CD25C330074CB35 /* RNFetchBlob.m in Sources */,
144144
);
145145
runOnlyForDeploymentPostprocessing = 0;

src/ios/RNFetchBlob/RNFetchBlob.m

+17-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "RCTBridge.h"
1111
#import "RCTEventDispatcher.h"
1212
#import "RNFetchBlobFS.h"
13-
#import "RNFetchBlobResp.h"
13+
#import "RNFetchBlobNetwork.h"
1414
#import "RNFetchBlobConst.h"
1515

1616

@@ -61,13 +61,13 @@ - (NSDictionary *)constantsToExport
6161
form:(NSArray *)form
6262
callback:(RCTResponseSenderBlock)callback)
6363
{
64-
64+
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
6565
// send request
6666
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
6767
initWithURL:[NSURL
68-
URLWithString: url]];
68+
URLWithString: encodedUrl]];
6969

70-
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[ FetchBlobUtils normalizeHeaders:headers]];
70+
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[ RNFetchBlobNetwork normalizeHeaders:headers]];
7171

7272

7373
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
@@ -76,9 +76,9 @@ - (NSDictionary *)constantsToExport
7676
// generate boundary
7777
NSString * boundary = [NSString stringWithFormat:@"RNFetchBlob%d", timeStampObj];
7878
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
79+
NSMutableData * postData = [[NSMutableData alloc] init];
7980
// if method is POST or PUT, convert data string format
8081
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
81-
NSMutableData * postData = [[NSMutableData alloc] init];
8282

8383
// combine multipart/form-data body
8484
for(id field in form) {
@@ -128,7 +128,7 @@ - (NSDictionary *)constantsToExport
128128

129129

130130
// send HTTP request
131-
FetchBlobUtils * utils = [[FetchBlobUtils alloc] init];
131+
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
132132
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
133133
});
134134
}
@@ -141,29 +141,33 @@ - (NSDictionary *)constantsToExport
141141
headers:(NSDictionary *)headers
142142
body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
143143
{
144+
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
144145
// send request
145146
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
146147
initWithURL:[NSURL
147-
URLWithString: url]];
148+
URLWithString: encodedUrl]];
148149

149-
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[FetchBlobUtils normalizeHeaders:headers]];
150+
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
150151
// move heavy task to another thread
151152
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
153+
NSMutableData * blobData;
152154
// if method is POST or PUT, convert data string format
153155
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
154156
// generate octet-stream body
155157
if(body != nil) {
156-
NSMutableData * blobData;
157158

158159
// when body is a string contains file path prefix, try load file from the path
159160
if([body hasPrefix:self.filePathPrefix]) {
160161
NSString * orgPath = [body substringFromIndex:[self.filePathPrefix length]];
161-
blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
162+
[request setHTTPBodyStream: [NSInputStream inputStreamWithFileAtPath:orgPath ]];
163+
// blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
162164
}
163165
// otherwise convert it as BASE64 data string
164-
else
166+
else {
165167
blobData = [[NSData alloc] initWithBase64EncodedString:body options:0];
166-
[request setHTTPBody:blobData];
168+
[request setHTTPBody:blobData];
169+
}
170+
167171
[mheaders setValue:@"application/octet-stream" forKey:@"content-type"];
168172

169173
}
@@ -173,7 +177,7 @@ - (NSDictionary *)constantsToExport
173177
[request setAllHTTPHeaderFields:mheaders];
174178

175179
// send HTTP request
176-
FetchBlobUtils * utils = [[FetchBlobUtils alloc] init];
180+
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
177181
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
178182
});
179183
}

src/ios/RNFetchBlobResp.h renamed to src/ios/RNFetchBlobNetwork.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//
2-
// RNFetchBlobResp.h
2+
// RNFetchBlobNetwork.h
33
// RNFetchBlob
44
//
5-
// Created by Ben Hsieh on 2016/6/6.
6-
// Copyright © 2016年 suzuri04x2. All rights reserved.
5+
// Created by wkh237 on 2016/6/6.
6+
// Copyright © 2016 wkh237. All rights reserved.
77
//
88

99
#ifndef RNFetchBlobResp_h
@@ -12,7 +12,7 @@
1212
#import <Foundation/Foundation.h>
1313
#import "RCTBridgeModule.h"
1414

15-
@interface FetchBlobUtils : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate> {
15+
@interface RNFetchBlobNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate> {
1616

1717
NSString * taskId;
1818
int expectedBytes;

0 commit comments

Comments
 (0)