I am using node to save an image into aws s3 storage with aws-sdk and multer midlleware.
I have a photo of a user and I am using a fixed name as key to object in aws S3.
When the user change the photo, I save it into aws s3 again with the same key.
My problem is that the photo in AWS is never updated.
I also tried to delete the object, before update it, but no look.
If I add a unique key to photo all works well.
Is possible update the photo and continues using the same key?
const storageS3 = multerS3({
s3: s3, //new aws.S3(),
bucket: process.env.BUCKET_NAME,
contentType: multerS3.AUTO_CONTENT_TYPE,
acl: "public-read",
key: async (req, file, cb) => {
const fileName = `${req.data.account_id}/empresas/empresa-${req.params.id}/profile/profile` +
path.extname(file.originalname);
cb(null, fileName);
}
});
const uploadProfileS3 = multer({
storage: storageS3,
limits: { fileSize: MAX_SIZE },
fileFilter: function(req, file, cb) {
checkFileType(file, cb);
},
}).single("file");