connect-busboy on('file') event not firing

和自甴很熟 提交于 2021-02-20 04:46:26

问题


I'm having issues with uploading files. I have the following code:

App.js

var bodyParser = require('body-parser');
var busboy = require('connect-busboy');

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(busboy({immediate: true, limits: {fileSize: 25 * 1024 * 1024}}));

Attachments.js

router.post('/:table/:id', function (req, res) {
    req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
        //Do stuff..
    });
});

The 'file' event is not firing. I tried logging, it does get into the route, so I don't think it's a routing issue. Any thoughts, what am I doing wrong?

Running versions:

  • Express : v4.x
  • Body-Parser : v1.11.0
  • connect-busboy : v0.0.2

回答1:


I know for me that my on file event would not fire because I was missing 'enctype="multipart/form-data"' in my form tag.

example:

<!-- inside my index.html -->

<form action="/" method="post" enctype="multipart/form-data">
<p> Files: <input class="data" type="file" name="img"> </p>
<input type="submit" value="Submit">
</form>


来源:https://stackoverflow.com/questions/28318002/connect-busboy-onfile-event-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!