I’m using Node.js + Express to build a web application, and I find the connect BodyParser that express exposes to be very useful in most cases. However, I would like to have more granular access to multipart form-data POSTS as they come – I need to pipe the input stream to another server, and want to avoid downloading the whole file first.
Because I’m using the Express BodyParser, however, all file uploads are parsed automatically and uploaded and available using "request.files" before they ever get to any of my functions.
Is there a way for me to disable the BodyParser for multipart formdata posts without disabling it for everything else?
When you type
app.use(express.bodyParser()), almost each request will go throughbodyParserfunctions (which one will be executed depends onContent-Typeheader).By default, there are 3 headers supported (AFAIR). You could see sources to be sure. You can (re)define handlers for
Content-Types with something like this:upd.
Things have changed in Express 3, so I’m sharing updated code from working project (should be
app.useed beforeexpress.bodyParser()):And some pseudo-code, regarding original question: