Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
Why does my code does not download the zip file in Nodejs

I Have been building a server which is gonna give out a zip file to download. It does not download the first time. But the second time it downloads. I use jimp to edit images and output those files into a specific directory.

app.use(
    '/api/edit',
    upload.single('image-file'),
    async (req, _res, next) => {
        const filePath = path.resolve(process.cwd(), 'user-data', req.file.filename);
        
        // resize every images
        await resizeAll(filePath);

        // continue request
        next();
    }
);

app.post('/api/allResize', upload.single('image-file'), (_req, res) => {
    // use res.setHeader to set the application file type to zip
    setHeaderAsZip(res);

    const zip = archiver('zip');
    zip.pipe(res);

    zip.directory('./user-data/icon-set-imagable', 'icon-set-imagable').finalize();

    res.on('close', () => {
        cleanUpIconData();
    });
});

The first time it generates the resizeAll output it sends a empty zip file but the second time it sends the file but do the cleanUpIconData, which clears out all data generated in the server.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda