As far as I know I need to place multer middleware before express-validator middleware in order to be able to access req.body from express-validator custom validators, like this:
app.post('/editPhoto',
upload.single('avatar'),
[express-validator middleware],
(req, res, next) => {
// req.file
//req.body
});
There are 2 options you can use to work with multer:
app.post('/editPhoto', upload.single('avatar'), [express-validator middleware],(req, res, next) => {
// req.file
//req.body
})
Or you can use:
app.post('/editPhoto', (req, res, next) => {
upload(req, res, function (err) {
if (err) {
// This is a good practice when you want to handle your errors differently
return
}
// Everything went fine
})
})
In the second option, you can handle Multer's errors, I would like to know if I could handle Multer's errors in the express-validator custom validators or in express route handling middleware if I use Multer as a middleware before the express-validator middleware, as in my first example