3

I am trying to download a file using web link with Javascript's XMLHttpRequest Object.I am not able to find out whether is it possible to pause a download and later resume it?

Rakesh_Kumar
  • 1,360
  • 1
  • 13
  • 27

2 Answers2

4

Technically it's possible, Without pause / resume you could just do a XmlHttpRequest with responseType "blob" and then forward the blob to the user via a link (instant download via click like mega)

But if you want a pause / resume i've read you must use the method abort of the XmlHttpRequest, create a temporary blob and when the user resume the download you need to start a new xhr from the byte where your previous request stop. After finishing the download (or a new abort occurs) you need to add all the new byte to the previous blob.

I need to try that, but the only limit (I think) can be a browser crash or a blob quota exed.

Sorry for my english, i'm a french frog ;)

CharlesD
  • 227
  • 1
  • 2
  • 5
1

you can do it but it also depends on the server ability to do so.

To "Pause", you can abort() your request and keep somewhere the already received response. How to cancel/abort jQuery AJAX request?

And to resume you have to ask the server to send only the missing parts. It is all about http ranges and partial contents. Here is some good reading about it : https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

Tuckbros
  • 387
  • 2
  • 12