@@ -85,14 +85,14 @@ - (id)init {
8585 return self;
8686}
8787
88- + (void ) enableProgressReport : (NSString *) taskId
88+ + (void ) enableProgressReport : (NSString *) taskId config : (RNFetchBlobProgress *) config
8989{
90- [progressTable setValue: @ YES forKey: taskId];
90+ [progressTable setValue: config forKey: taskId];
9191}
9292
93- + (void ) enableUploadProgress : (NSString *) taskId
93+ + (void ) enableUploadProgress : (NSString *) taskId config : (RNFetchBlobProgress *) config
9494{
95- [uploadProgressTable setValue: @ YES forKey: taskId];
95+ [uploadProgressTable setValue: config forKey: taskId];
9696}
9797
9898// removing case from headers
@@ -221,11 +221,6 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
221221 if ([response respondsToSelector: @selector (allHeaderFields )])
222222 {
223223 NSDictionary *headers = [httpResponse allHeaderFields ];
224- if (expectedBytes < 0 )
225- {
226- expectedBytes = [[headers valueForKey: @" Content-Length" ] intValue ];
227-
228- }
229224 NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases: @" Content-Type" fromHeaders: headers] lowercaseString ];
230225 if (respCType != nil )
231226 {
@@ -329,8 +324,9 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
329324 {
330325 [writeStream write: [data bytes ] maxLength: [data length ]];
331326 }
332-
333- if ([progressTable valueForKey: taskId] == @YES )
327+ RNFetchBlobProgress * pconfig = [progressTable valueForKey: taskId];
328+ NSNumber * now =[NSNumber numberWithFloat: ((float )receivedBytes/(float )expectedBytes)];
329+ if (pconfig != nil && [pconfig shouldReport: now])
334330 {
335331 [self .bridge.eventDispatcher
336332 sendDeviceEventWithName: EVENT_PROGRESS
@@ -433,13 +429,15 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
433429// upload progress handler
434430- (void ) URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didSendBodyData : (int64_t )bytesSent totalBytesSent : (int64_t )totalBytesWritten totalBytesExpectedToSend : (int64_t )totalBytesExpectedToWrite
435431{
436- if ([uploadProgressTable valueForKey: taskId] == @YES ) {
432+ RNFetchBlobProgress * pconfig = [uploadProgressTable valueForKey: taskId];
433+ NSNumber * now = [NSNumber numberWithFloat: ((float )totalBytesWritten/(float )totalBytesExpectedToWrite)];
434+ if (pconfig != nil && [pconfig shouldReport: now]) {
437435 [self .bridge.eventDispatcher
438436 sendDeviceEventWithName: EVENT_PROGRESS_UPLOAD
439437 body: @{
440438 @" taskId" : taskId,
441439 @" written" : [NSString stringWithFormat: @" %d " , totalBytesWritten],
442- @" total" : [NSString stringWithFormat: @" %d " , bodyLength ]
440+ @" total" : [NSString stringWithFormat: @" %d " , totalBytesExpectedToWrite ]
443441 }
444442 ];
445443 }
0 commit comments