busboy将不会收到上传的文件

我的表单很简单。 它使用ng-flow来处理file upload:

<form class="form-horizontal" enctype="multipart/form-data"> <div flow-init="{target: '/test', testChunks: false, query: {'_csrf': '{{csrf}}', 'somestring': 'teststring'} }" flow-files-submitted="data.flow.upload()" flow-name="data.flow"> <input type="file" flow-btn/> </div> </form> 

一旦图像被选中, ng-flow将对目标path执行POST。 看起来像图像是由于请求有效负载有一堆像这样发送的:

 1048576 ------WebKitFormBoundaryw2YAG9m602ICPd0Q Content-Disposition: form-data; name="flowCurrentChunkSize" 

图像不是很大(〜1MB)

在nodejs端(带有express):

 var busboy = require('connect-busboy')({ limits: { fileSize: 10 * 1024 * 1024 } }); router.post('/test', busboy, function(req, res) { console.log('test called'); console.log(req.busboy); if (req.busboy) { req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { console.log("this is fieldname: " + fieldname); }); req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) { console.log('Field [' + fieldname + ']: value: ' + inspect(val)); }); } res.json(); }); 

req.busboy返回一个充满东西的对象,但是req.busboy.on('file'...req.busboy.on('field'...)永远不会触发。

为什么不是看着我的string和图像?

您需要将请求传送给busboy,以便它可以parsing表单:

 req.pipe(req.busboy);