Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 8108330

Browse files
committed
Add Android increment HTTP support
1 parent cedbf95 commit 8108330

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class RNFetchBlobConfig {
1919
public String mime;
2020
public Boolean auto;
2121
public long timeout = 60000;
22+
public Boolean increment = false;
2223
public ReadableArray binaryContentTypes = null;
2324

2425
RNFetchBlobConfig(ReadableMap options) {
@@ -35,6 +36,7 @@ public class RNFetchBlobConfig {
3536
this.binaryContentTypes = options.getArray("binaryContentTypes");
3637
this.key = options.hasKey("key") ? options.getString("key") : null;
3738
this.mime = options.hasKey("contentType") ? options.getString("contentType") : null;
39+
this.increment = options.hasKey("increment") ? options.getBoolean("increment") : false;
3840
this.auto = options.hasKey("auto") ? options.getBoolean("auto") : false;
3941
if(options.hasKey("timeout")) {
4042
this.timeout = options.getInt("timeout");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ public Response intercept(Chain chain) throws IOException {
292292
extended = new RNFetchBlobDefaultResp(
293293
RNFetchBlob.RCTContext,
294294
taskId,
295-
originalResponse.body());
295+
originalResponse.body(),
296+
options.increment);
296297
break;
297298
case FileStorage:
298299
extended = new RNFetchBlobFileResp(
@@ -305,7 +306,8 @@ public Response intercept(Chain chain) throws IOException {
305306
extended = new RNFetchBlobDefaultResp(
306307
RNFetchBlob.RCTContext,
307308
taskId,
308-
originalResponse.body());
309+
originalResponse.body(),
310+
options.increment);
309311
break;
310312
}
311313
return originalResponse.newBuilder().body(extended).build();

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.facebook.react.modules.core.DeviceEventManagerModule;
1010

1111
import java.io.IOException;
12+
import java.nio.charset.Charset;
1213

1314
import okhttp3.Call;
1415
import okhttp3.Callback;
@@ -30,11 +31,13 @@ public class RNFetchBlobDefaultResp extends ResponseBody {
3031
String mTaskId;
3132
ReactApplicationContext rctContext;
3233
ResponseBody originalBody;
34+
boolean isIncrement = false;
3335

34-
public RNFetchBlobDefaultResp(ReactApplicationContext ctx, String taskId, ResponseBody body) {
36+
public RNFetchBlobDefaultResp(ReactApplicationContext ctx, String taskId, ResponseBody body, boolean isIncrement) {
3537
this.rctContext = ctx;
3638
this.mTaskId = taskId;
3739
this.originalBody = body;
40+
this.isIncrement = isIncrement;
3841
}
3942

4043
@Override
@@ -71,6 +74,13 @@ public long read(Buffer sink, long byteCount) throws IOException {
7174
args.putString("taskId", mTaskId);
7275
args.putString("written", String.valueOf(bytesRead));
7376
args.putString("total", String.valueOf(contentLength()));
77+
if(isIncrement) {
78+
args.putString("chunk", sink.readString(Charset.defaultCharset()));
79+
}
80+
else {
81+
args.putString("chunk", "");
82+
}
83+
7484
rctContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
7585
.emit(RNFetchBlobConst.EVENT_PROGRESS, args);
7686
}

0 commit comments

Comments
 (0)