Rn-fetch-blob: `progress` dose no work in iOS because`setProgress` will call before `sendRequest`

Created on 2 Jul 2018  路  8Comments  路  Source: joltup/rn-fetch-blob

When I fetch a file like that:

FetchBlob
    .fetch('GET','xxx')
    .progress({ interval : 250},(receive,total)=>{
      console.log("progress", receive/total)
    })

I can't receive progress because progress will be called synchronization with fetch.

In iOS:

  • fetch will call :
RCT_EXPORT_METHOD(fetchBlob:(NSDictionary *)options
                  taskId:(NSString *)taskId
                  method:(NSString *)method
                  url:(NSString *)url
                  headers:(NSDictionary *)headers
                  body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
  • progress will call:
RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)

The fetchBlob function will async create an request obj.
Before the buildOctetRequest 's onComplete is called ,enableProgressReport has already been called.
Caused enableProgressReport can't find taskID

RCT_EXPORT_METHOD(fetchBlob:(NSDictionary *)options
                  taskId:(NSString *)taskId
                  method:(NSString *)method
                  url:(NSString *)url
                  headers:(NSDictionary *)headers
                  body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
{
    [RNFetchBlobReqBuilder buildOctetRequest:options
                                      taskId:taskId
                                      method:method
                                         url:url
                                     headers:headers
                                        body:body
                                  onComplete:^(NSURLRequest *req, long bodyLength)
    {
        // something went wrong when building the request body
        if(req == nil)
        {
            callback(@[@"RNFetchBlob.fetchBlob failed to create request body"]);
        }
        // send HTTP request
        else
        {
            [[RNFetchBlobNetwork sharedInstance] sendRequest:options
                                               contentLength:bodyLength
                                                      bridge:self.bridge
                                                      taskId:taskId
                                                 withRequest:req
                                                    callback:callback];
        }
    }];
}
bug help wanted

Most helpful comment

I have to do like this

let fetchobj = FetchBlob.fetch(
      'GET',
      'xxxx'
    )

    setTimeout(()=>{
      fetchobj.progress({ interval: 250},(resive,total)=>{
        console.log("progress", resive/total)
      })
    }, 0)

    fetchobj.then((res)=>{
      console.log("res", res)
    })

All 8 comments

I have to do like this

let fetchobj = FetchBlob.fetch(
      'GET',
      'xxxx'
    )

    setTimeout(()=>{
      fetchobj.progress({ interval: 250},(resive,total)=>{
        console.log("progress", resive/total)
      })
    }, 0)

    fetchobj.then((res)=>{
      console.log("res", res)
    })

I'm having the same issue and @MJXin's workaround fixed it.

I've also had uploadProgress stop working similarly.

I've also had uploadProgress stop working similarly.

the same problem, but @MJXin's workaround not fixed for me.

this.lastRNBFTask = RNFetchBlob.config({
            // response data will be saved to this path if it has access right.
            path: tempCacheFile,
        })
            .fetch(
                ...
            );

            setTimeout(()=>{
              this.lastRNBFTask.progress({ interval: 250},(received ,total)=>{
                console.log(received / total);
              })
            }, 0);

        this.lastRNBFTask
            .then(async (res) => {
               ...
            })
            .catch(async (error) => {
               ...
            });

RN-Fetch-Blob: v0.10.12
RN: v0.55.4
OS: iOS 11.4

hey guys, i fix it in the PR, #155

@yurnery
Great, this PR works for me.

PR is merged

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

bony06aug picture bony06aug  路  3Comments

developercode1 picture developercode1  路  3Comments

drewandre picture drewandre  路  4Comments

Jeijie picture Jeijie  路  3Comments