问题
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