【发布时间】:2018-12-21 15:11:38
【问题描述】:
我有一个express 路由,用于上传文件,通过formData 发送到服务器。
假设文件是.rar 或.zip 文件,我的目标是提取所有文件名,即在此压缩文件夹或其子文件夹中。
这是我的express 路由当前的样子:
module.exports = async (req, res) => {
try {
const busboy = new Busboy({ headers: req.headers })
busboy.on('finish', async () => {
const fileData = req.files.file
console.log(fileData)
// upload file
// send back response
})
req.pipe(busboy)
} catch (err) { return response.error(req, res, err, 'uploadProductFile_unexpected') }
}
这是console.log(fileData) 的样子:
{
data:
<Buffer 52 61 72 21 1a 07 01 00 56 0c 22 93 0c 01 05 08 00 07 01 01 8d d6 8d 80 00 85 76 33 e4 49 02 03 0b fc d4 0d 04 b1 8c 1e 20 bc 86 da 2e 80 13
00 2b 66 ... >,
name: 'filename.rar',
encoding: '7bit',
mimetype: 'application/octet-stream',
truncated: false,
size: 224136
}
在filename.rar 内部有一些文件,例如texture.png 和info.txt。我的目标是获取这些名称。
【问题讨论】:
标签: node.js file zip rar busboy