I'm trying to create a file selection / download.
I use JSZip for creating the .zip file and Filesaver.js for the download part.
It works fine with 'text/plain' MIME type on both Firefox and Chrome but not working with the blob returned by JSZip which is an 'application/zip' MIME on Firefox.
Here are both blob console.log results on Firefox :
Here is the code:
function handleDownloadRequest(ids){
//Define files urls
//Some code to fill the fileUrls array
var fileUrls = []
...
//Download & zip
const zip = new JSZip();
let count = 0;
const zipFilename = 'Files_Archive' + new Date().toLocaleDateString() +'.zip'
fileUrls.forEach(async function (url) {
console.log(url)
const urlArr = url.split('/');
const filename = urlArr[urlArr.length - 1];
try {
const file = await JSZipUtils.getBinaryContent(url)
zip.file(filename, file, { binary: true });
count++;
if (count === fileUrls.length) {
zip.generateAsync({ type: 'blob' })
.then(function (content) {
//Working
/*let blob = new Blob(["Hello, world!"], { type: "text/plain;charset=utf-8" });
console.log(blob)
FileSaver.saveAs(blob, "hello world.txt");*/
//Not working on Firefox
console.log(content)
FileSaver.saveAs(content, zipFilename);
});
}
} catch (err) {
console.log(err);
}
});
}
In JSZip's documentation there's a part where they talk about a different behavior of the saveAs function on Firefox but that didn't help me :
Under the hood, the polyfill uses the native saveAs from the FileSaver API (on Chrome and IE10+) or use a Blob URL (on Firefox).
Any clue will be much appreciated