Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda