req.busboy.on('file') not firing

吃可爱长大的小学妹 提交于 2021-01-27 05:15:22

问题


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

Inside 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 triggers, but the 'file' doesn't.

Inside app.js I have:

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

Any ideas?


回答1:


Your file field is missing a name attribute.



来源:https://stackoverflow.com/questions/31186192/req-busboy-onfile-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!