最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Reading content of zip using JSZip - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jan 25, 2017 at 15:34 مسعودمسعود 68910 silver badges26 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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);                         

                    });                                             
            }); 
发布评论

评论列表(0)

  1. 暂无评论