【问题标题】:busboy won't receive uploaded filesbusboy 不会收到上传的文件
【发布时间】:2015-04-14 21:15:32
【问题描述】:

我的表格很简单。它使用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 没有看到我的字符串和图像?

【问题讨论】:

    标签: javascript node.js express busboy


    【解决方案1】:

    您需要将请求传递给 busboy,以便它可以解析表单:

    req.pipe(req.busboy);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2020-04-05
      • 2016-05-08
      • 2016-07-11
      • 2017-05-15
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多