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

Problem with canceling the request #140

Open
Spisaczek opened this issue Aug 7, 2018 · 10 comments
Open

Problem with canceling the request #140

Spisaczek opened this issue Aug 7, 2018 · 10 comments

Comments

@Spisaczek
Copy link

Spisaczek commented Aug 7, 2018

Specs:
"react-native": "0.55.4",
"rn-fetch-blob": "0.10.12",

Hello guys :)

So I have a problem with canceling request. I'm trying to download some huge apk file (more than 400 MB) and I want to give user ability to cancel the download process.

So I'm creating the request in this way:

let request = RNFetchBlob.config({
             path: apkPath,
             fileCache: true
        }).fetch('GET', app.apkDownloadUrl)
           .then((res) => {[...]});

Then, when I call:

request.cancel();

There is error that says that "cancel" is not a function.
What I'm doing wrong? :)

BTW: Beside this issue, great library!

@emision
Copy link

emision commented Aug 24, 2018

Try to put in request
RNFetchBlob.config({ path: apkPath, fileCache: true }).fetch('GET', app.apkDownloadUrl)
and after
request.then((res) => {[...]}); request.cancel();

@ithustle
Copy link

I have an issue maybe is a bug, I don't know. When I request a cancel the promise of success is triggered.

this.task = config(options).fetch('GET', url);
            this.task.progress((received, total) => {
                let progress_value = received / total;
                this.setState({ progress_value });
            });
            this.task.then((res) => {
                // Success handle - When I call _cancelDownload() this promise is triggered
                }).catch(err => console.log(err))  
            });
        }
    }

    _cancelDownload() {
        
        this.task.cancel((err, taskId) => {
            // Handle cancl
        });
        
    }

@HasanAlyazidi
Copy link

Same issue on Android as @ithustle explained, and i do not know if the issue also happens on iOS.

@ithustle
Copy link

ithustle commented Feb 2, 2019

@HasanAlyazidi only on Android. On IOS is working propertly

@HasanAlyazidi
Copy link

I managed to solve it with this workaround

    ...
    this.isCancelled = false; // <-- step 1 (needed if you want to retry downloading)

    this.task = config(options).fetch('GET', url);
    
    this.task.progress((received, total) => {
        let progress_value = received / total;
        this.setState({ progress_value });
    });

    this.task.then((res) => {
        if (this.isCancelled) return;  // <-- step 2

        // save to db/redux, etc...
    })
    .catch(err => console.log(err))
    ...

    _cancelDownload() {
        this.isCancelled = true; // <-- step 3

        this.task.cancel((err, taskId) => {
            // Handle cancelling
        });
    }

@b3hz4d
Copy link

b3hz4d commented Mar 17, 2019

I have an issue maybe is a bug, I don't know. When I request a cancel the promise of success is triggered.

this.task = config(options).fetch('GET', url);
            this.task.progress((received, total) => {
                let progress_value = received / total;
                this.setState({ progress_value });
            });
            this.task.then((res) => {
                // Success handle - When I call _cancelDownload() this promise is triggered
                }).catch(err => console.log(err))  
            });
        }
    }

    _cancelDownload() {
        
        this.task.cancel((err, taskId) => {
            // Handle cancl
        });
        
    }

Same problem here
calling cancel when download is in middle of it, it will trigger success promise and going into then function

@nadav2051
Copy link

Experiencing the same issue.
Canceling a download in iOS produced a promise rejection.
Canceling a download with android returns success and no indication of the cancellation.
I'm currently using the workaround posted by @HasanAlyazidi which works fine, but it would be so much nicer to have the library behaving consistently =)

@DillionApple
Copy link

Same issue as @ithustle explained. And @HasanAlyazidi 's workaround may face the problem when the download is canceled because of network error, not canceled by hand.

@andho
Copy link

andho commented Aug 9, 2019

I think this PR #381 fixes it.

@majirosstefan
Copy link

I do not why, but on iOS canceling the request is quite unreliable. Running on simulator, it happens pretty often that cancel method call is ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants