If you need to use the functionality provided by express.bodyParser
but you want to disable it for multipart/form-data, the trick is to not use express.bodyParser directly
. express.bodyParser
is a convenience method that wraps three other methods: express.json
, express.urlencoded
, and express.multipart
.
So instead of saying
app.use(express.bodyParser())
you just need to say
app.use(express.json())
.use(express.urlencoded())
This gives you all the benefits of the bodyparser for most data while allowing you to handle formdata uploads independently.
Edit: json
and urlencoded
are now no longer bundled with Express. They are provided by the separate body-parser module and you now use them as follows:
bodyParser = require("body-parser")
app.use(bodyParser.json())
.use(bodyParser.urlencoded())