req.busboy.on('file')未触发 [英] req.busboy.on('file') not firing

查看:76
本文介绍了req.busboy.on('file')未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的格式如下:

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

encoder_post 内部,我具有以下函数来处理发布请求:

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.

app.js 内部,我有:

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

有什么想法吗?

推荐答案

您的文件字段缺少 name 属性.

Your file field is missing a name attribute.

这篇关于req.busboy.on('file')未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆