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

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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