我的表格很简单。它使用 ng-flow处理文件上传:
<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
将向目标路由执行 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'...)
永远不会触发。
为什么公交车男孩看不到我的字符串和图像?
最佳答案
您需要将请求通过管道传递给busboy,以便它可以解析表单:
req.pipe(req.busboy);
关于javascript - Busboy不会收到上传的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29637536/