Reputation: 35
Goal: I have an array of <a>
that I loop through to download with element.click
. With this method, the files are downloaded 1 by 1. I would rather them be downloaded in a folder instead, as the array can reach up to 3 digit lengths.
Is this possible on the client side?
Current Code:
<button onClick={ () => {
projectScreens.forEach( (item, index) => {
htmlToImage.toJpeg(document.getElementById(index + 'Export'), { pixelRatio: 6 })
.then(function (dataUrl) {
const link = document.createElement('a');
link.download = 'Screen ' + (index + 1) + '.jpeg';
link.href = dataUrl;
link.click();
});
});
}}>export</button>
(htmlToImage.toJpeg just converts an element in the DOM into jpeg)
Upvotes: 2
Views: 3587
Reputation: 1883
Browser/HTTP does not support downloading more than one file at a time.
There are 2 solutions:
However, there is a tool that might be your help. Check this out https://github.com/sindresorhus/multi-download
Upvotes: 2