routing-controllers
routing-controllers copied to clipboard
question: Access `request.body` in `@UseBefore` for `multipart/form-data`
Hey guys!
I saw a similar question already, but not exactly. Also I haven't found satisfying answers there as well.
The case:
In my current project I use Joi
to validate input data within @UseBefore
hook. It looks more or less like this:
@UseBefore(someValidationHandler)
action(@UploadedFile('file') file: any) {
// ...
}
Now the problem is that when I am sending a multipart/form-data
request I get empty request.body
inside @UseBefore
. That's of course because body-parser
(which I am also using) does not support multipart data but... also because multer
middleware is run after @BeforeUse
hooks (I've checked ExpressDriver
) .
So my question is: is there a reason why multer
middleware can't be run before beforeMiddlewares
inside ExpressDriver
?
I did some testing and it seems to be working without any issues. I could even prepare a PR for that.