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

192
Vistas
Web Server saving images as 0 bytes

When I send an image to my web server through an http request, it manages to save the original image with its full size. But when I attempt to resize the image, it saves it as 0 bytes. Im using an npm module called sharp to do the image resizing. When I do any resizing, even massive resizing jobs on my local machine, there are no issues. Running this code on my Apache web server causes it to not actually save the images most of the time. It seems completely random which images it actually saves. The only consistent part is that it saves the original image sent through the http request.

In my filesystem there will be the original image EG: abcdefg.jpg, and then abcdefg-350x350.jpg will be 0 bytes.

        const results = await temp.mv(path.resolve(folderName + name + '.' + extension))

        bluebird.map(sizes, (size) => {
            sharp(folderName + name + '.' + extension)
                .resize(size.w, size.h, {
                    fit: 'cover'
                })
                .toFile(folderName + name + '-' + size.w + 'x' + size.h + '.' + extension)
            console.log('Resized image')
        })
        .then(() => {
            console.log('Images were resized')
            if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'testing') {
                console.log('Images resized and going back');
                res.status(200).json({'location': '/imageserving/uploads/' + year + '/' + month + '/' + name + '.' + extension, fileIndex: '1'});
            }
            else if (process.env.NODE_ENV === 'production') {
                //possibly use req.hostname
                res.status(200).json({'location': 'mysite/uploads/' + year + '/' + month + '/' + name + '.' + extension, fileIndex: '1'});
            }   
        })
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try updating this line:

sharp(folderName + name + '.' + extension)

to this:

return sharp(folderName + name + '.' + extension)

...that should make sure the following then() section is properly chained to the promise and avoids potential race conditions that may be causing the inconsistent behavior.

over 4 years ago · Santiago Trujillo Denunciar
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