1
votes

I have a code where I am generating the zipped file with images in it.

var zip = new JSZip(result.templateEncoded, {base64: true});

The zipped file structure looks something like this:

{ "files":
        {
          "test/rel":{
                      "name":"xxx.txt"
                     },
          "test/doc.xml":{
                         "name":"kajdadnkan"
                         },
          "test/media/image1.jpeg":{
                                   "name": "word/media/image1.jpeg"
                                   },
          "test/media/image1.jpeg":{
                                   "name": "word/media/image2.jpeg"
                                   }
        }
}

Now I want to access all images under "test/media". When I tried zip.folder('word/media/'); it creates a new folder and sets the root path to 'word/media/'

Also tried below code but it throws JS error forEach() is not supported function.

zip.folder('word').forEach(function (relativePath, file){
                            console.log("iterating over..", relativePath);
                        });

Basically, I want to extract all media files and rename them to .png. I don't have much exposure here so appreciate any help.

1

1 Answers

0
votes
 var contentTypesettings = zip.files["test/media"].asText();
var CTXMLDoc = $.parseXML(contentTypesettings);
$(CTXMLDoc).find('Default').each(function() {
    $.each(this.attributes, function(i, attrib) {
        var attrName = attrib.name;
        var attrValue = attrib.value;
     });