Billy
Billy

Reputation: 1104

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

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:

Upvotes: 0

Views: 1502

Answers (1)

BIggie Emmanuel
BIggie Emmanuel

Reputation: 11

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>

Upvotes: 1

Related Questions