Amanda
Amanda

Reputation: 127

How to do parallel downloads of videos using XMLHttpRequest in javascript? Is there any solution to do chunk by chunk?

I am trying to download multiple large video files from Google cloud storage (30 MB - 1 GB size). Currently I am downloading sequentially using XMLHttpRequest as below and storing in local memory using FileSystem API.

var xhr = new XMLHttpRequest(); 
xhr.open('GET', Url, true); // url is my google cloud storage url
xhr.responseType = 'blob';
xhr.onload = function (e) {
    blob = xhr.response;
};
xhr.send();

I am using blob to store the video files.As it is blob, it will be stored in RAM and we cannot do parallel downloads in this way.Is there any way to download the videos chunk by chunk or any other alternatives as I also found that blob can only store upto 500Mib

Upvotes: 1

Views: 773

Answers (1)

kzahel
kzahel

Reputation: 2785

Add a range header to the XMLHTTPRequest using setRequestHeader to get file offsets. HTTP Range docs. You can use FileWriter and .seek to write at the appropriate offsets.

Upvotes: 2

Related Questions