本文介绍了无法使用JSZip下载文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要 zip 并下载一个文件夹.我似乎找不到答案. JSZip似乎只下载文件.
I am wanting to zip and download a folder. I can't seem to find out how. JSZip seems to only download files.
我不想使用PHP.
最后,我希望它通过链接下载,例如< a href ='#'> Download</a>.
Last thing, I want it to download with a link, like <a href='#'>Download</a>.
推荐答案
只需继续调用zip.file().从他们的 http://stuk.github.io/jszip/
Just keep calling zip.file().Look at the example from their http://stuk.github.io/jszip/
例如如下所示:
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;
重要的是要了解您编写的代码-了解每一行的功能.如果这样做,您将意识到只需再次调用zip.file()即可添加另一个文件.
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.
这篇关于无法使用JSZip下载文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!