|
@@ -116,7 +116,7 @@ function fetch(...args:any):Promise {
|
116
|
116
|
// create task ID for receiving progress event
|
117
|
117
|
let taskId = getUUID()
|
118
|
118
|
let options = this || {}
|
119
|
|
- let subscription, subscriptionUpload, stateEvent
|
|
119
|
+ let subscription, subscriptionUpload, stateEvent, partEvent
|
120
|
120
|
let respInfo = {}
|
121
|
121
|
|
122
|
122
|
let promise = new Promise((resolve, reject) => {
|
|
@@ -143,6 +143,12 @@ function fetch(...args:any):Promise {
|
143
|
143
|
}
|
144
|
144
|
})
|
145
|
145
|
|
|
146
|
+ partEvent = emitter.addListener('RNFetchBlobServerPush', (e) => {
|
|
147
|
+ if(e.taskId === taskId && promise.onPartData) {
|
|
148
|
+ promise.onPartData(e.chunk)
|
|
149
|
+ }
|
|
150
|
+ })
|
|
151
|
+
|
146
|
152
|
// When the request body comes from Blob polyfill, we should use special its ref
|
147
|
153
|
// as the request body
|
148
|
154
|
if( body instanceof Blob && body.isRNFetchBlobPolyfill) {
|
|
@@ -168,9 +174,11 @@ function fetch(...args:any):Promise {
|
168
|
174
|
subscription.remove()
|
169
|
175
|
subscriptionUpload.remove()
|
170
|
176
|
stateEvent.remove()
|
|
177
|
+ partEvent.remove()
|
171
|
178
|
delete promise['progress']
|
172
|
179
|
delete promise['uploadProgress']
|
173
|
180
|
delete promise['stateChange']
|
|
181
|
+ delete promise['part']
|
174
|
182
|
delete promise['cancel']
|
175
|
183
|
promise.cancel = () => {}
|
176
|
184
|
|
|
@@ -229,6 +237,10 @@ function fetch(...args:any):Promise {
|
229
|
237
|
RNFetchBlob.enableUploadProgressReport(taskId, interval, count)
|
230
|
238
|
return promise
|
231
|
239
|
}
|
|
240
|
+ promise.part = (fn) => {
|
|
241
|
+ promise.onPartData = fn
|
|
242
|
+ return promise
|
|
243
|
+ }
|
232
|
244
|
promise.stateChange = (fn) => {
|
233
|
245
|
promise.onStateChange = fn
|
234
|
246
|
return promise
|