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

How we can cancel or pause downloading files using dio? #399

Closed
1 task
Zeeshan0201 opened this issue Aug 2, 2019 · 15 comments
Closed
1 task

How we can cancel or pause downloading files using dio? #399

Zeeshan0201 opened this issue Aug 2, 2019 · 15 comments

Comments

@Zeeshan0201
Copy link

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name e.g. flutter / ios / android
Platform Version e.g. 1.5.0 / 12.0 / 9.0
Dio Version e.g. 2.1.0 / 1.0.17
Android Studio / Xcode Version e.g. Android Studio 3.3.2 / Xcode 10.2.1
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

@sokryptk
Copy link

sokryptk commented Aug 2, 2019

CancelToken cancelToken = CancelToken;

dio.download(
    cancelToken: cancelToken,
);

Now from anywhere just,
cancelToken.cancel()

As for pause/resume support, better wait for @wendux.

EDIT:

Actually, pause/resume also works, but you have to supply the header range:1222-19238, then append the files.
This downloads the file where you left off at (you will have to calculate the downloaded file size)

@stale
Copy link

stale bot commented Sep 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Sep 1, 2019
@stale stale bot closed this as completed Sep 8, 2019
@kareemX
Copy link

kareemX commented Jul 29, 2020

Have you found a solution?

@deepashree-ballodi
Copy link

How we can Pause and continue downloading where we stopped exactly?

@sokryptk
Copy link

sokryptk commented Aug 8, 2020 via email

@4-alok
Copy link

4-alok commented Dec 23, 2020

+1

@sokryptk
Copy link

Edited my original comment.

@Omi231
Copy link

Omi231 commented Jan 1, 2021

Edited my original comment.

Can you explain in a bit more detail for noobs like me? Thanks

@mikezander
Copy link

@krypticallusion

EDIT:

Actually, pause/resume also works, but you have to supply the header range:1222-19238, then append the files.
This downloads the file where you left off at (you will have to calculate the downloaded file size)

Can you give a simple example? What do you mean by append the files?

@sokryptk
Copy link

sokryptk commented Dec 3, 2021

@krypticallusion

EDIT:

Actually, pause/resume also works, but you have to supply the header range:1222-19238, then append the files. This downloads the file where you left off at (you will have to calculate the downloaded file size)

Can you give a simple example? What do you mean by append the files?

I can't right now give you the exact working sample, sorry.
But here is how it goes :

Z = "The File to be downloaded"

Once you cancel() a download, You should have the file that dio wrote to.
Check the size of the corrupt file.

Issue another download with the range supplied. Suppose you paused the download at 1MB out of 14Mb so (1048576).
Now while calling the download method, supply range:1048576- (No need of the end byte position since you're gonna be downloading the whole thing). Now you have two files, one that has downloaded upto 1048576 bytes while the other file has downloaded from 1048577 to the end of file. Now open the first file with FileMode.APPEND, and write the second file to the first file.

@sokryptk
Copy link

sokryptk commented Dec 3, 2021

@Ahmed-Sellami
Copy link

Why doesn't the package offer the possibility to use FileMode.append instead of FileMode.write instead of downloading chunks and then merging them?

RandomAccessFile raf = file.openSync(mode: FileMode.write);

@sokryptk
Copy link

Why doesn't the package offer the possibility to use FileMode.append instead of FileMode.write instead of downloading chunks and then merging them?

RandomAccessFile raf = file.openSync(mode: FileMode.write);

Beats the point, you can't have parallel file writes at the same point in time at different file locations. That's simply not possible. That's why we create some temporary files that can be parallel-ly written to, then stitch them back together. Hope this helps.

@Khushnu
Copy link

Khushnu commented Jul 1, 2024

any solution guys ? for pause and resume ?

@kostov
Copy link

kostov commented Jul 17, 2024

@Khushnu,
just read the solution above :)
#399 (comment)
I also starting to implement this.

@cfug cfug locked as off-topic and limited conversation to collaborators Jul 17, 2024
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

10 participants