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

187
Visualizações
Reduced file size after uploading to S3 bucket from nodejs

I am trying to upload files from a particular folder location to a sample S3 bucket. I am using standard nodejs aws-sdk for this. Files are deepzoom images (.dzi) files. Files are getting uploaded to my S3 bucket but the contents of the file are not getting uploaded properly. Like I am uploading images of sizes 800B, but after uploading the size of image is only 7B. I tried downloading it to see its content but the file doesn't contains the image but just the file name. This is the code I am running for uploading files:

function read(file, numFiles) {
fs.readFile(file, function (err, data) {
  if (err) console.log(err);
  const fileContent = Buffer.from(file, "binary");
  s3.putObject(
    {
      Bucket: "sample-bucket",
      Key: file,
      Body: fileContent,
    },
    function (resp) {
      console.log(arguments);
      console.log("Successfully uploaded, ", file);
      uploadCount++;
      console.log("uploadcount is:", uploadCount);
      if (uploadCount == numFiles) {
        res.send("All files uploaded");
      }
    }
  ).on("httpUploadProgress", (evt) => {
    console.log(`Uploaded ${evt.loaded} out of ${evt.total}`);
  });
});

}

I am passing files to this read function from another function. I am not sure why this is happening. Any help would be appreciated.

Before uploading image properties:

enter image description here

Property of image uploaded to S3 bucket:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Buffer.from(file) will not return the content of the file but return the buffer of the argument, this time the argument is "file". So the file uploaded to S3 has filename as contents.

Try to change this line

const fileContent = Buffer.from(file, "binary");

to like this.

const fileContent = fs.readFileSync(file);
about 4 years ago · Juan Pablo Isaza 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