Ich versuche, ein paar Bilddateien herunterzuladen, und speichern Sie es in einer einzigen Zip-Datei mit JavaScript und JSZip. Aber das gibt eine leere Zip-Datei zurück. Was mache ich falsch? Ich verwende JSZip und JSZip-utilsBilder herunterladen und als Zip mit JSZip und JS-Zip Utils herunterladen
function createZip() {
//Create zip file object
var zip = new JSZip();
//Add folders
//Add files
JSZipUtils.getBinaryContent("icons/8_Bit_Character.png", function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file("picture.png", data, {binary:true});
});
JSZipUtils.getBinaryContent("icons/16_Bit_Character.png", function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file("picture2.png", data, {binary:true});
});
//Compile all the data into memory.
var base64 = null;
if (JSZip.support.uint8array) {
promise = zip.generateAsync({type : "uint8array"});
} else {
promise = zip.generateAsync({type : "string"});
}
//Generate the zip file and download it.
zip.generateAsync({type:"base64"}).then(function (base64) {
location.href="data:application/zip;base64," + base64;
});
}