Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

I can't stop a download. #94

Open
AnderAmorim opened this issue Dec 1, 2020 · 5 comments
Open

I can't stop a download. #94

AnderAmorim opened this issue Dec 1, 2020 · 5 comments

Comments

@AnderAmorim
Copy link

AnderAmorim commented Dec 1, 2020

Hello, I need help to stop a download.

I tried as follows:

let task = RNBackgroundDownloader.download ({
 id: 'file123',
 url: 'https: //link-to-very.large/file.zip'
 destination: `$ {RNBackgroundDownloader.directories.documents} / file.zip`
}). begin ((expectedBytes) => {
 console.log (`Going to download $ {expectedBytes} bytes!`);
}). progress ((percent) => {
 console.log (`Downloaded: $ {percent * 100}%`);
}). done (() => {
 console.log ('Download is done!');
}). error ((error) => {
console.log ('Download canceled due to error:', error);
});
task.stop ();

However, when calling task.stop the download is not stopped. When giving a console.log in task.stop I get undefined.

I also tried to list downloads in progress and outline the task I wanted to stop:

async function stopDownload(download);
    let lostTasks = await RNBackgroundDownloader.checkForExistingDownloads ();
    for (let task of lostTasks) {
      if (task.id == download.id) {
        task.stop
      }
    };

With that I get the following error:
Captura de Tela 2020-12-01 às 17 12 16

@AnderAmorim
Copy link
Author

Any solution?

@sidferreira
Copy link

@AnderAmorim I had this issue, I just changed it to _${downloadId}

@AnderAmorim
Copy link
Author

Thanks for the suggestion Sidferreira. But where more specifically would this change be made? I couldn't see it exactly.

@sidferreira
Copy link

When you start the download, you are setting the id with a value that works as int. If you change id: 123 to id: "_123" it might address the issue

@AnderAmorim
Copy link
Author

I understand now. I will check if this is the error.
Once again, thank you very much!

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

No branches or pull requests

2 participants