Pavan Kumar
Pavan Kumar

Reputation: 1891

Failing to create zip file in node express: Error 21

I am trying to create zip file using express as follows.

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();
});

The file gets downloaded. But when I try to open it I get Error 21 as shown in the following screenshot.

enter image description here

Upvotes: 1

Views: 92

Answers (0)

Related Questions