Closed hacksparrow closed 10 years ago
Yes it is compatible. This module is basically just a thin wrapper to attach a busboy instance to the req
object. What are you having trouble with in particular?
The post handler keeps hanging there; even the busboy events handlers are not executed. The "here!" message is printed, though.
var busboy = require('connect-busboy');
// load the middleware
app.use(busboy({ immediate: true }));
// define a POST route
app.post('/', function(req, res) {
if (req.method === 'POST') {
console.log('here!');
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log(filename);
});
req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
console.log(key, value);
});
}
});
Am I doing something wrong?
You're not sending a response to the request. Using immediate: true
can be tricky because you could miss events if connect-busboy
and the route handler are not called within the same tick.
Well, I am not concerned about sending the response at the moment, I want to get the busboy events firing first. I am not getting the console.log messages.
I have removed immediate: true
, still not helping.
If you remove immediate: true
, then you have to pipe the request yourself: req.pipe(req.busboy);
Updated code. No busboy events fired.
var busboy = require('connect-busboy');
// load the middleware
app.use(busboy());
// define a POST route
app.post('/', function(req, res) {
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log(filename);
});
req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
console.log(key, value);
});
req.busboy.on('finish', function() {
console.log('OVER!');
res.send('OK!');
});
req.pipe(req.busboy);
});
It works for me:
var busboy = require('connect-busboy'),
app = require('express')();
app.get('/', function(req, res) {
res.send('<html><head></head><body>\
<form method="POST" enctype="multipart/form-data">\
<input type="text" name="textfield"><br />\
<input type="file" name="filefield"><br />\
<input type="submit">\
</form>\
</body></html>');
});
// load the middleware
app.use(busboy());
// define a POST route
app.post('/', function(req, res) {
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('file', filename);
file.resume();
});
req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
console.log('field', key, value);
});
req.busboy.on('finish', function() {
console.log('OVER!');
res.send('OK!');
});
req.pipe(req.busboy);
});
app.listen(8000);
I got it. It happens if enctype
is not multipart/form-data
.
Try without the enctype
attribute or with its value set to application/x-www-form-urlencoded
.
It still works for me even when I remove the enctype
or specify application/x-www-form-urlencoded
explicitly.
Express version? I am using 4.2.0.
Upgraded to 4.3.2, still the same.
Sorry for not including all the details. The culprit was bodyParser.urlencoded()
.
Are Busboy and bodyParser
mutually exclusive?
busboy can do both application/x-www-form-urlencoded
and multipart/form-data
.
body-parser only supports application/x-www-form-urlencoded
and application/json
.
Is connect-busboy compatible with busboy 0.2.6? Been hacking for almost an hour, can't get it working.
Maybe update the examples to make the usage more obvious?