'Problem with downloading multiple files with one button with Retool
I want to download multiple files at once with a button event in Retool. How can I do this with Retool? As another method, I first tried to collect all the files in a folder and download them with zip. But it created corrupt zip file.
I've seen posts about this issue on the Retool forum:
- https://community.retool.com/t/download-a-blob-to-file/4608
- https://community.retool.com/t/create-a-zip-file-in-retool/4906
const zip = new JSZip();
let count = 0;
const urls = [
'https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSxl70GnCvkJzbeZ4vle5wSSOkbfcFiH6jGqxZ-v5seew5g9REYFQ1kEGa04ACE5wrLgSk&usqp=CAU',
];
urls.forEach(function(url){
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) throw err;
count++;
zip.file(`image-${count}.jpg`, data, {binary:true});
if (count == urls.length) {
zip.generateAsync({type:'blob'}).then(function(content) {
utils.downloadFile(url, 'zipImages','zip');
});
}
});
});
Retool doc: https://docs.retool.com/docs/scripting-retool#utilsdownloadfiledata-filename-filetype
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
