Created
July 30, 2018 12:03
-
-
Save VivienAdnot/daf2c6843c194ff8e93ad9ed04907904 to your computer and use it in GitHub Desktop.
busboy case 2: console.log chunks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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