1

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 Answers1

0

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.

Tanvi B
  • 1,577
  • 11
  • 14
  • I actually meant "Zip a folder that was already there" instead of creating a folder, and putting files in it. I've already seen examples like this. – JumboUser155 Jun 04 '16 at 03:31