Created
July 30, 2018 12:02
-
-
Save VivienAdnot/d5ddb1bed7f124721052fc75d2c03c59 to your computer and use it in GitHub Desktop.
busboy case 1: write file to disk
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
var http = require('http'); | |
var fs = require('fs'); | |
var Busboy = require('busboy'); | |
http.createServer(function(req, res) { | |
var busboy = new Busboy({ | |
headers: req.headers | |
}); | |
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | |
var saveTo = 'uploaded.txt'; | |
file.pipe(fs.createWriteStream(saveTo)); | |
}); | |
busboy.on('finish', function() { | |
res.writeHead(200, { | |
'Connection': 'close' | |
}); | |
res.end("That's all folks!"); | |
}); | |
return req.pipe(busboy); | |
}).listen(8001, function() { | |
console.log('server3 is listening for requests on 8001'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment