I am new to Nodejs and want to send response code 404 when the file mimetype is not png or jpeg.
As well as I want to send response code 404 if the file size is greater than 5mb.
I am doing it with this code and I am getting this error in the log on nodejs.
router.post("/insertNewProduct", auth, receive.single('productUrl'), async (req, res) => {
try {
if (req.file.mimetype !== 'image/jpeg' && file.mimetype !== 'image/png') {
res.status(404).send({
message: "Column productUrl can only accept jpeg or png image",
data: {}
})
} else if (req.file.size > (1024 * 1024 * 5)) {
res.status(404).send({
message: "Image size can not be greater that 5mb.",
data: {}
})
}else{
//Add Product to db
}
} catch (e) {
res.status(404).send({
message: e,
data: {}
});
}
});