使用 JSZip 读取 zip 的内容
Reading content of zip using JSZip
我正在上传一个 zip 文件夹并尝试读取其 XML 文件。该函数可以使用 JSZip 读取 zip 但无法检索 XML 文件的内容。
readasText 需要一个 blob 对象,我尝试了不同的东西,但它总是给出类型错误。
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);
}
});
}
}
我想将 XML 结果提供给 GetvalueFile 函数
文件对象在 zip.files 中,但我无法检索它。
对于可能遇到相同问题的任何人
zip.files['test1.xml'].async("string")// gives the content of xml
它 returns 一个可以用来触发更多功能的承诺
.then(function(zip) {
zip.files['test1.xml'].async("string")
.then(function (data) {
GetValueFile(data);
});
});
我正在上传一个 zip 文件夹并尝试读取其 XML 文件。该函数可以使用 JSZip 读取 zip 但无法检索 XML 文件的内容。
readasText 需要一个 blob 对象,我尝试了不同的东西,但它总是给出类型错误。
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);
}
});
}
}
我想将 XML 结果提供给 GetvalueFile 函数 文件对象在 zip.files 中,但我无法检索它。
对于可能遇到相同问题的任何人
zip.files['test1.xml'].async("string")// gives the content of xml
它 returns 一个可以用来触发更多功能的承诺
.then(function(zip) {
zip.files['test1.xml'].async("string")
.then(function (data) {
GetValueFile(data);
});
});