Tuesday, 10 September 2013

Play nice, node-formidable and express.bodyParser

Play nice, node-formidable and express.bodyParser

I used to do app.use(express.bodyParser()); to allow me to get POST bodies
in my ordinary (non-file) routes.
I then had to implement multi-file uploads, so I introduced
node-formidable. For the the only single route for which I need
node-formidable's functionality, I instantiate it explicitly and use it
from there:
var form = new formidable.IncomingForm({ uploadDir:__dirname +
'/public/uploads' });
What I now need is to get back to being able to parse textual POST data
without having formidable interfere with that. Sadly, as soon as I
reintroduce app.use(express.bodyParser()); into my script, then attempts
to parse images using node-formidable as described above, will fail.
Is there any easy way to get around this? Can I not use node-formidable's
bodyParser to deal with everything? If so, how would I do that?

No comments:

Post a Comment