I'm trying to upload a file to AWS S3 with multer using upload.single('image') but no matter what I do, req.file always returns undefined. I'm using postman to submit the form. I've tried the exact same code in a new project and it works. But when I try it in my main project, it won't work.
const upload = multer({
storage: multerS3({
s3: s3,
bucket: "bucketName",
acl: "public-read",
metadata: function (req: Request, file: any, cb: any) {
cb(null, { fieldName: file.fieldname });
},
key: function (req: Request, file: any, cb: any) {
cb(null, Date.now().toString());
},
}),
});
router.post(
"/upload",
upload.single("image"),
(req: Request, res: Response) => {
console.log(req.file);
console.log(req.files);
return res.json({ status: "OK" });
}
);