0

I use JSZIP and FileSaver to do the job, which I wanted to put multiple images into a zip to download it at the client side. Below code worked for text.

var zip = new JSZip();
zip.file("abc.txt", "this is the content");

zip.generateAsync({type:"blob"}).then(function (blob) {
   saveAs(blob, "hello.zip");
});

My problem is I have this http://example.com/abc.png. What should I do? convert the image to base64 first?

Please give me some hint to proceed thanks

Maria Jane
  • 2,353
  • 6
  • 23
  • 39
  • Below code worked for text. Ok. And for images? – GolezTrol Sep 17 '16 at 08:43
  • I don't know that's why I'm asking – Maria Jane Sep 17 '16 at 08:57
  • Hey guest271314, this is different question please. – Maria Jane Sep 17 '16 at 08:58
  • Maria Jane: it is (almost) the same question: to add the content of the image, you need to download it first. The only difference is that you operate on a binary content and the linked question uses a text content: use `httpRequest.responseType = "arraybuffer" or "blob"` (see [the documentation](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType)) and read from `httpRequest.response` instead of `httpRequest.responseText`. See also [this page](http://stuk.github.io/jszip/documentation/howto/read_zip.html) from the JSZip documentation. – David Duponchel Sep 17 '16 at 18:36

0 Answers0