Skip to content

Instantly share code, notes, and snippets.

@VivienAdnot
Created July 30, 2018 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VivienAdnot/daf2c6843c194ff8e93ad9ed04907904 to your computer and use it in GitHub Desktop.
Save VivienAdnot/daf2c6843c194ff8e93ad9ed04907904 to your computer and use it in GitHub Desktop.
busboy case 2: console.log chunks
const http = require('http');
const inspect = require('util').inspect;
const Busboy = require('busboy');
http.createServer(function(req, res) {
const busboy = new Busboy({
headers: req.headers
});
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function(data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
busboy.on('finish', function() {
console.log('Done parsing form!');
res.end();
});
req.pipe(busboy);
}).listen(8000, function() {
console.log('server2 is listening for requests on 8000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment