I'm trying to validation my form before i upload images but i getting empty string on my middleware
const upload = multer({
storage: storage
});
router.post('/upload', formsValidation, upload.fields([{
name: 'images',
maxCount: 20
}, {
name: 'imageMain',
maxCount: 1
}]), function(req, res, next) {
code...
});
heres my middleware:
function formsValidation (req, res, next) {
console.log(req.body) //getting empty array here
return next();
}
i know that i can use fileFilter from multer but some times i dont have any images to upload just string to store and validate, i have tried to parse the req.body from multipart/form-data to string then validate and use next() but i get a range error, any ideia how can i solve this?