我有以下表格: 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-
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里面,我有以下函数来处理post请求:
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); });
但是,每当我提交表单时,“字段”处理程序都会触发,但“文件”不会触发.
在app.js里面我有:
var busboy = require('connect-busboy'); app.use(busboy());
有任何想法吗?
您的文件字段缺少名称属性.