Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress dose no work in iOS becausesetProgress will call before sendRequest #96

Closed
MJXin opened this issue Jul 2, 2018 · 8 comments
Closed
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@MJXin
Copy link

MJXin commented Jul 2, 2018

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];
        }
    }];
}
@MJXin
Copy link
Author

MJXin commented Jul 2, 2018

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)
    })

@diegolmello
Copy link

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

@Traviskn Traviskn added bug Something isn't working help wanted Extra attention is needed labels Jul 11, 2018
@milesmatthias
Copy link

I've also had uploadProgress stop working similarly.

@qiaolin-pan
Copy link

I've also had uploadProgress stop working similarly.

@wonday
Copy link

wonday commented Aug 20, 2018

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

@yurnery
Copy link

yurnery commented Aug 20, 2018

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

@wonday
Copy link

wonday commented Aug 20, 2018

@yurnery
Great, this PR works for me.

@Traviskn
Copy link

PR is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants