Download Mutiple Files From The Browser At Once – multi-download

Category: Javascript , Recommended | June 14, 2019
Author: sindresorhus
Views Total: 104
Official Page: Go to website
Last Update: June 14, 2019
License: MIT

Preview:

Download Mutiple Files From The Browser At Once – multi-download

Description:

multi-download is a pure JavaScript library which allows the user to download and rename multiple files from the browser at once.

How to use it:

Install and import the multi-download library.

# NPM
$ npm install multi-download --save

Insert the multi-download library into the document.

<script src="browser.js"></script>

Create a download button and specify the files paths in the data-files attribute.

<button id="download-rename-button" 
        data-files="1.zip 2.zip 3.zip">
        Download multiple files and rename them
</button>

The JavaScript to download multiple files once you click the download button.

document.querySelector('#download-rename-button').addEventListener('click', event => {
  const files = event.target.dataset.files.split(' ');

  multiDownload(files, {
    rename: ({url, index, urls}) => {
      const extension = url.slice(url.lastIndexOf('.') + 1);
      return `file${index}.${extension}`;
    }
  });
});

You Might Be Interested In:


Leave a Reply