|
|
|
|
77
|
static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
|
77
|
static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
|
78
|
static ConnectionPool pool = new ConnectionPool();
|
78
|
static ConnectionPool pool = new ConnectionPool();
|
79
|
|
79
|
|
80
|
- MediaType contentType = RNFetchBlobConst.MIME_OCTET;
|
|
|
81
|
ReactApplicationContext ctx;
|
80
|
ReactApplicationContext ctx;
|
82
|
RNFetchBlobConfig options;
|
81
|
RNFetchBlobConfig options;
|
83
|
String taskId;
|
82
|
String taskId;
|
|
|
|
|
94
|
ResponseType responseType;
|
93
|
ResponseType responseType;
|
95
|
WritableMap respInfo;
|
94
|
WritableMap respInfo;
|
96
|
boolean timeout = false;
|
95
|
boolean timeout = false;
|
97
|
- public boolean reportProgress = false;
|
|
|
98
|
- public boolean reportUploadProgress = false;
|
|
|
99
|
|
96
|
|
100
|
public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
|
97
|
public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
|
101
|
this.method = method.toUpperCase();
|
98
|
this.method = method.toUpperCase();
|
|
|
|
|
398
|
case KeepInMemory:
|
395
|
case KeepInMemory:
|
399
|
try {
|
396
|
try {
|
400
|
// For XMLHttpRequest, automatic response data storing strategy, when response
|
397
|
// For XMLHttpRequest, automatic response data storing strategy, when response
|
401
|
- // header is not `application/json` or `text/plain`, write response data to
|
|
|
402
|
- // file system.
|
|
|
|
|
398
|
+ // data is considered as binary data, write it to file system
|
403
|
if(isBlobResp && options.auto == true) {
|
399
|
if(isBlobResp && options.auto == true) {
|
404
|
String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
|
400
|
String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
|
405
|
InputStream ins = resp.body().byteStream();
|
401
|
InputStream ins = resp.body().byteStream();
|
|
|
|
|
418
|
// #73 Check if the response data contains valid UTF8 string, since BASE64
|
414
|
// #73 Check if the response data contains valid UTF8 string, since BASE64
|
419
|
// encoding will somehow break the UTF8 string format, to encode UTF8
|
415
|
// encoding will somehow break the UTF8 string format, to encode UTF8
|
420
|
// string correctly, we should do URL encoding before BASE64.
|
416
|
// string correctly, we should do URL encoding before BASE64.
|
421
|
- String utf8Str;
|
|
|
422
|
byte[] b = resp.body().bytes();
|
417
|
byte[] b = resp.body().bytes();
|
423
|
CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
|
418
|
CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
|
424
|
try {
|
419
|
try {
|
|
|
|
|
426
|
// if the data can be encoded to UTF8 append URL encode
|
421
|
// if the data can be encoded to UTF8 append URL encode
|
427
|
b = URLEncoder.encode(new String(b), "UTF-8").replace("+", "%20").getBytes();
|
422
|
b = URLEncoder.encode(new String(b), "UTF-8").replace("+", "%20").getBytes();
|
428
|
}
|
423
|
}
|
429
|
- // This usually mean the data is binary data
|
|
|
430
|
- catch(CharacterCodingException e) {
|
|
|
431
|
-
|
|
|
432
|
- }
|
|
|
|
|
424
|
+ // This usually mean the data is contains invalid unicode characters, it's
|
|
|
425
|
+ // binary data
|
|
|
426
|
+ catch(CharacterCodingException ignored) {}
|
433
|
finally {
|
427
|
finally {
|
434
|
callback.invoke(null, null, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
|
428
|
callback.invoke(null, null, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
|
435
|
}
|
429
|
}
|
|
|
|
|
439
|
}
|
433
|
}
|
440
|
break;
|
434
|
break;
|
441
|
case FileStorage:
|
435
|
case FileStorage:
|
442
|
- try{
|
|
|
|
|
436
|
+ try {
|
443
|
// In order to write response data to `destPath` we have to invoke this method.
|
437
|
// In order to write response data to `destPath` we have to invoke this method.
|
444
|
// It uses customized response body which is able to report download progress
|
438
|
// It uses customized response body which is able to report download progress
|
445
|
// and write response data to destination path.
|
439
|
// and write response data to destination path.
|
446
|
resp.body().bytes();
|
440
|
resp.body().bytes();
|
447
|
- } catch (Exception ignored) {
|
|
|
448
|
-
|
|
|
449
|
- }
|
|
|
|
|
441
|
+ } catch (Exception ignored) {}
|
450
|
callback.invoke(null, null, this.destPath);
|
442
|
callback.invoke(null, null, this.destPath);
|
451
|
break;
|
443
|
break;
|
452
|
default:
|
444
|
default:
|