Req.busboy.on ('file') does not fire

I have the following form:

form(method='post', action='/encoder_post', enctype='multipart/form-data')
    .form-group
        label(for='name') Name
        input.form-control(type='text', id='name', name='name')
    .form-group
        label(for='message') Message
        input.form-control(type='text', id='message', name='message')
    .form-group
        label(for='file') Audio File (*.wav)
        input.form-control(type='file', id='file')
    button.btn.btn-cicada.btn-block(type='submit') Submit

      

Internally encoder_post

, I have the following function to handle the post request:

router.post('/', function(req, res){
    req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
        console.log("this is in file");
    });
    req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
        console.log("The value is: " + value);
    });
    req.pipe(req.busboy);
});

      

However, whenever I submit the form, the "field" handler is triggered, but the "file" doesn't work.

Inside app.js

I have:

var busboy = require('connect-busboy');
app.use(busboy());

      

Any ideas?

+3


source to share


1 answer


Your file field is missing an attribute name

.



+10


source







All Articles