1

我正在尝试使用 express 创建 zip 文件,如下所示。

const archiver = require('archiver');

app.get('/path/download', async (req, res) => {
    const arch = archiver('zip');
    arch.append('abc', { name: 'abc.txt'});
    arch.append('cdf', { name: 'cdf.txt'});
    arch.append('efg', { name: 'efg.txt'});
    res.set('Content-Type', 'application/zip');
    res.set('Content-Disposition', 'attachment; filename=test.zip');
    arch.pipe(res);
    arch.finalize();
});

文件被下载。但是当我尝试打开它时,我得到Error 21如下屏幕截图所示。

在此处输入图像描述

4

0 回答 0