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

Category: Javascript , Recommended | October 18, 2021
Author:sindresorhus
Views Total:213 views
Official Page:Go to website
Last Update:October 18, 2021
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
import multiDownload from 'multi-download';

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.

// Vanilla JS
document.querySelector('#download-button').addEventListener('click', event => {
  const files = event.target.dataset.files.split(' ');
  multiDownload(files);
});
// With jQuery
$('#download-button').on('click', () => {
  const files = $(this).data('files').split(' ');
  multiDownload(files);
});
// With Blob
const unicorn = URL.createObjectURL(new Blob([blobData], {type: 'text/plain'}));
const goat = URL.createObjectURL(new Blob(['blobData'], {type: 'text/plain'}));
multiDownload([unicorn, goat]);

Changelog:

v4.0.0 (10/18/2021)

  • This package is now pure ESM.

You Might Be Interested In:


Leave a Reply