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

206
Views
cant view image that I downloaded using aws-sdk and wrote to disk using node

Im downloading an image (.png file) on my express server from an s3 bucket using the aws-sdk for node and then writing it to the disk using fs.writeFileSync. the problem is when I try to view the image on my computer, it says: is appears that we dont support this file format. I checked properties of the downloaded images and its 37.2 KB so it means something was returned.

Is this not the correct way to download the image?

here is my code:

function downloadFile(fileKey) {
  const downloadParams = {
    Key: fileKey,
    Bucket: bucketName,
  };
  return s3.getObject(downloadParams).promise();
}


router.get("/getImage", async (req, res) => {
  try {
    let image= await downloadFile(`${req.query.imageID}.png`);
    fs.writeFileSync(`Images/${req.query.image}.png`, image);

    res.status(200).send();
  } catch (e) {
    console.log(e);
    res.status(500).send(e);
  }
});




about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

in your code please make sure you passed the correct parameter to fs.writeFileAsync. as I can see plot instead of the image.

second please make sure to download the image directly from the s3 and make sure you are able to view it on your computer if not you have to add the 'Content-Type': 'image/png' while uploading the image to s3.

about 4 years ago · Santiago Trujillo Report

0

My mistake was that I writing the full s3 result to the disk(image) and not the Body from the result. this is the correct code:

 fs.writeFileSync(`Images/${req.query.taskID}-plot.png`, image.Body);
about 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!