当前位置:网站首页>Jszip get the file of the specified file in the uploaded zip package
Jszip get the file of the specified file in the uploaded zip package
2022-06-11 10:38:00 【Come and play games with people】
Use scenarios :
For bulk upload . Because a single upload requires upload fields , file , Therefore, batch uploading requires uploading excel and zip package . excel Record multiple pieces of data , A single entry in the data includes field values , Some field values are zip The corresponding file name in the package , Read the corresponding... According to the value file file , For single upload .
Installation package
npm i jszip -S
Secondary package plug-in
zipGetFile.js
import JSZip from 'jszip';
const parse_zip = (file_data, fileName)=> {
return new Promise((resolve, reject) => {
JSZip.loadAsync(file_data).then((zip) => {
zip.files[fileName].async('blob').then((blob) => {
// this.readTextAs(blob, "UTF-8").then(e => {
// resolve(e);
// }).catch(e => {
// reject(e);
// });
console.log(blob);
let files = new window.File(
[blob],
fileName,
{
type: blob.type }
);
resolve(files);
console.log(files);
})
}).catch(e => {
reject(e);
})
})
}
const parse_data = (file_data, fileName) => {
return new Promise((resolve, reject) => {
parse_zip(file_data, fileName).then(e => {
resolve(e)
// let data = null;
// try {
// data = JSON.parse(e);
// }
// catch (e) {
// data = null;
// }
// data ? resolve(data) : reject(null);
}).catch(e => {
reject(e);
})
});
}
const readTextAs = (arrayBuffer, encoding) => {
return new Promise((resolve, reject) => {
var reader = new FileReader();
var blob = new Blob([arrayBuffer]);
reader.onload = function (evt) {
resolve(evt.target.result);
};
reader.onerror = function (evt) {
reject(null);
};
reader.readAsText(blob, encoding);
}).catch(e => {
reject(e);
})
}
export default parse_data
Use
zipGetFile(zip file , file name ).then(res => {
})
边栏推荐
猜你喜欢
随机推荐
< Pytorch series 4 & gt;: Constructing neural network model
Install MySQL version 5.7 or above on windows (install in compressed package)
【MYSQL】存储过程的使用
Record yesterday's embarrassment
Linker and linker options, runtime libraries and runtime library settings, configuration settings, build process and methods
RSA signature issues
Circuit board made of real gold -- golden finger
用真金做的电路板——金手指
Série de démarrage C # (XI) - - tableaux multidimensionnels
Some code fragments of a universal and confession wall system developed by PHP
Leetcode 1952. 三除数
Batch add noise to data and generate new named annotation files
Development and source code construction of digital collection system
[Objective-C] dynamically create controls
NGUI,聊天滚动框,UI TextList
修复UICollectionView 没有到达底部安全区的问题
Cloud image quality assistant IAPP source code
班组级安全培训,新员工入职培训教育课件,全内容PPT套用
Summary of common constraints in MySQL foundation part I
【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode








