routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

question: Access `request.body` in `@UseBefore` for `multipart/form-data`

Open przemczan opened this issue 2 years ago • 0 comments

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.

przemczan avatar Jul 13 '21 10:07 przemczan