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:
Property of image uploaded to S3 bucket:

