2

When using Busboy with express to handle image uploads, I can get the fields and files of a multipart/form-data post like so:

var busboy = require('connect-busboy');
app.use(busboy());
app.post('/something', function(req,res) {
    req.pipe(req.busboy);
    req.busboy.on('field', function(fieldname, val) {
         // do stuff here with fields... 
    }
    req.busboy.on('file', function (fieldname, file, filename) {
        // do stuff here with the file
    }
});

What I'm wondering is, say there's an instance where I want to know what the fields are before I go about handling the file. It appears in my experimentation that the fields are gotten first every time. Does anyone know if this is guaranteed to always be the case?

Benjamin Thvedt
  • 351
  • 1
  • 3
  • 17
  • were you able to solve this? I am in a similar situation. – darshanz Aug 27 '15 at 12:17
  • I do think I had a solution, but it was long ago and I abandoned the project. However if memory serves, what I did in my particular case (I think) was I used "req.busboy.on('finish', function() {.." The 'finish' doesn't fire until everything is done, so in my file and field handlers all I did was store the values and then once the 'finish' function fired is when I did stuff with them. – Benjamin Thvedt Aug 29 '15 at 02:13

0 Answers0