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

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

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