Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download multiple files as a zip or in a folder using Javascript?

Is it possible to download multiple files from an url into one created folder or as a zip?

I currently download a file given a url like so:

var download_url = ""; 
window.location.href = download_url;

If I were to have an array of urls, I could do something like...

for each url in urls
    window.location.href = url;

This works, but will lead to individual downloaded files in the downloads folder. This can be messy.

Is it possible to create and specify which folder to download all of the files or convert all the downloaded files into a zip?

like image 335
Rohan Avatar asked Nov 01 '22 08:11

Rohan


1 Answers

In modern browsers, you could convert all the downloaded files into a zip with a combination of JSZip (https://stuk.github.io/jszip/) and AJAX blob downloads (Using jQuery's ajax method to retrieve images as a blob), although I expect you will run into performance issues when dealing with large files. Otherwise, it isn't possible to create a folder on the client with browser JS.

like image 74
David Noël Avatar answered Nov 09 '22 08:11

David Noël