Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading content of zip using JSZip

I am uploading a zip folder and trying to read its XML file. The function can read the zip using JSZip but unable to retrieve the content of XML file.

readasText needs a blob object, I tried different things but it always gives type error.

  upload: function (e) {
                $("#fullPath").val(e.files[0].name);
                if ($.browser.msie == undefined || ($.browser.msie && $.browser.version < 10) == false) {
                    $("#fullPath").val(e.files[0].name);

                    var zipFile = new JSZip();
                    zipFile.loadAsync(e.files[0].rawFile)
                    .then(function(zip) {

                        var reader = new FileReader();
                        reader.readAsText(zip.files);// type error: dont know how to access the xml file 
                        reader.onloadend = function () {
                            GetValueFile(reader.result);
                        }                           
                    });                                    
                }
            }

I want to give the XML result to the GetvalueFile function The file object is inside zip.files but I'm unable to retrive it.

like image 506
مسعود Avatar asked Sep 07 '25 16:09

مسعود


1 Answers

For anyone who might have the same problem

zip.files['test1.xml'].async("string")// gives the content of xml

It returns a promise which can be used to trigger further functions

            .then(function(zip) {

                zip.files['test1.xml'].async("string")
                .then(function (data) {
                        GetValueFile(data);                         

                    });                                             
            }); 
like image 136
مسعود Avatar answered Sep 10 '25 06:09

مسعود