Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!