Looking at the source for formidable
's form.parse()
, you should be able to do mimic most of what it's doing internally.
Another solution might be to use something like busboy
which gives you a plain old parser stream to write to, so you might end up with something like:
var Busboy = require('busboy');
var bb = new Busboy({ headers: { 'content-type': '....' } });
bb.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [%s]: filename=%j; encoding=%j; mimetype=%j',
fieldname, filename, encoding, mimetype);
file.on('data', function(data) {
console.log('File [%s] got %d bytes', fieldname, data.length);
}).on('end', function() {
console.log('File [%s] Finished', fieldname);
});
}).on('field', function(fieldname, val) {
console.log('Field [%s]: value: %j', fieldname, val);
}).on('finish', function() {
console.log('Done parsing form!');
});
bb.end(someBuffer);