Search code examples
meteorjszip

JSZipUtils undefined using Meteor


I have been trying to use JSZip to download image files to the client. Many solutions I have come across use JSZipUtils to extract the data required for the image when passed to JSZip.

What I have so far:

var logoUrl = '/images/logo.jpg';

const downloadPromise = new Promise(resolve => {
  JSZipUtils.getBinaryContent(logoUrl, (err, data) => resolve(data));
});

zip.file('logo.jpg', downloadPromise);

zip.generateAsync({type:"blob"}).then(function(content) {
  saveAs(content, "example.zip");
}, function(err) {
  console.log(err);
});

The problem seems to be with JSZipUtils, which I thought was added as part of the udondan:jszip package. To my dismay, it wasn't.

Could anyone tell/show me how to add JSZipUtils to my Meteor project, as there doesn't seem to be a package available?


Solution

  • I was missing the import declaration at the top of my meteor js file.

    import JSZipUtils from "/client/lib/jszip-utils.js" 
    

    After adding this I was able to use the JsZipUtils library.

    There is a lack of documentation out there to assist with this.

    I hope this can help someone else!