当前位置:网站首页>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 => {
})
边栏推荐
- jszip 获取上传的zip包中的指定文件的file
- Wechat cloud development al short video one click face changing applet source code
- 【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
- Window management learn more about windowmanagerservice
- Use of kingbasees UDP monitoring tool for gold warehouse database
- C语言课程设计题目
- IPhone 15 forced to use type-C interface
- Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
- 【DBSCAN】DBSCAN实例
- Leetcode 1995. Statistics special quads (brute force enumeration)
猜你喜欢

Summary of common constraints in MySQL foundation part I

beginning一款非常优秀的emlog主题

MXNet对AlexNet模型的构建与实现(与LeNet的对比)
Implementing declarative rest calls using feign

为什么DDRx的电源设计时需要VTT电源

Jedislock redis distributed lock implementation

Explain the physical layer consistency test of 2.5g/5g/10g Base-T Ethernet interface in detail!

TikTok在英国遭遇文化冲突,短期内众多员工离职

NFT products are alive

Install MySQL version 5.7 or above on windows (install in compressed package)
随机推荐
硬件描述语言HDL
使用RSA与base64对字符串进行加密解密
Leetcode 1995. Statistics special quads (brute force enumeration)
Linker and linker options, runtime libraries and runtime library settings, configuration settings, build process and methods
Batch add noise to data and generate new named annotation files
金仓数据库KingbaseES中的PL/SQL 编译检查
NGUI,聊天滚动框,UI TextList
Implementing declarative rest calls using feign
[Objective-C] differences between structs and classes
FPGA infrastructure [reference ug998]
EMC rectification cases of electronic equipment radiation
Ngui, map zoom in and out
Explain the physical layer consistency test of 2.5g/5g/10g Base-T Ethernet interface in detail!
利用PHP开发的一款万能、表白墙系统部分代码片段
Finite cyclic group
Unity字体间距
[audio and video] Introduction to SEI
基于C语言实现比赛评分系统
International multilingual sea mall rebate product automatic matching order source code
吴恩达机器学习课程-第七周