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

213
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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