GithubHelp home page GithubHelp logo

standardgalactic / multi-download Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sindresorhus/multi-download

0.0 2.0 0.0 322 KB

Download multiple files at once in the browser

Home Page: https://sindresorhus.com/multi-download/

License: MIT License

JavaScript 57.54% HTML 42.46%

multi-download's Introduction

multi-download

Download multiple files at once in the browser

It works by abusing the a-tag download attribute.

Install

$ npm install multi-download

Note: This package targets the latest versions of Chrome, Firefox, and Safari.

Usage

<button id="download-button" data-files="unicorn.jpg rainbow.jpg">Download</button>
const multiDownload = require('multi-download');

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

// With jQuery
$('#download-button').on('click', () => {
	const files = $(this).data('files').split(' ');
	multiDownload(files);
});
const multiDownload = require('multi-download');

// With Blob
const unicorn = URL.createObjectURL(new Blob(['๐Ÿฆ„'], {type: 'text/plain'}));
const goat = URL.createObjectURL(new Blob(['๐Ÿ'], {type: 'text/plain'}));
multiDownload([unicorn, goat]);

API

multiDownload(urls, options?)

Returns a Promise that resolves when all the downloads have started.

Note that there's a delay of 1 second between each download.

urls

Type: string[]

URLs to files you want to download. Can be absolute or relative, even cross-origin.

options

Type: object

rename

Type: Function

A function tht accepts an object containing url, index, and urls properties and is expected to return the new filename.

<button id="download-button" data-files="unicorn.jpg rainbow.jpg">Download</button>
const multiDownload = require('multi-download');

document.querySelector('#download-button').addEventListener('click', event => {
	const files = event.target.dataset.files.split(' ');
	multiDownload(files, {
		rename: ({url, index, urls}) => 'New name.pdf'
	});
});

Caveats

If the user has enabled "Ask where to save each file before downloading" in Chrome, it will only download the first file.

multi-download's People

Contributors

cbbfcd avatar gpetrites avatar mathiasbynens avatar morrislaptop avatar sergeydarnopykh avatar sindresorhus avatar stryju avatar yuler avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.