Can't download folder with JSZip

我的梦境 提交于 2020-03-03 07:46:31

问题


I am wanting to zip and download a folder. I can't seem to find out how. JSZip seems to only download files.

I don't want to have to use PHP.

Last thing, I want it to download with a link, like <a href='#'>Download</a>.


回答1:


Just keep calling zip.file(). Look at the example from their http://stuk.github.io/jszip/

for example like below :

var zip = new JSZip();

// Add a text file with the contents "Hello World\n"
zip.file("Hello.txt", "Hello World\n");

// Add a another text file with the contents "Goodbye, cruel world\n"
zip.file("Goodbye.txt", "Goodbye, cruel world\n");

// Add a folder named "images"
var img = zip.folder("images");

// Add a file named "smile.gif" to that folder, from some Base64 data
img.file("smile.gif", imgData, {base64: true});

var content = zip.generate();
location.href="data:application/zip;base64,"+content;

The important thing is to understand the code you've written - learn what each line does. If you do this, you'd realize that you just need to call zip.file() again to add another file.



来源:https://stackoverflow.com/questions/37624807/cant-download-folder-with-jszip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!