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 · 7 comments

Comments

Projects
None yet
6 participants
@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

This comment has been minimized.

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

This comment has been minimized.

Copy link

ithustle commented Nov 29, 2018

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

This comment has been minimized.

Copy link

HasanAlyazidi commented Feb 2, 2019

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

@ithustle

This comment has been minimized.

Copy link

ithustle commented Feb 2, 2019

@HasanAlyazidi only on Android. On IOS is working propertly

@HasanAlyazidi

This comment has been minimized.

Copy link

HasanAlyazidi commented Feb 6, 2019

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

nadav2051 commented Mar 28, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.