Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var http = require('http');
var fs = require('fs');
var Busboy = require('busboy');
var PORT = 6666;
http.createServer(function(req, res) {
if (req.url === '/') {
res.writeHead(200, {'content-type': 'text/html'});
res.end('<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="file" name="upload" multiple="multiple" onchange="this.parentNode.submit()">'+
'</form>');
} else if (req.url === '/upload') {
var busboy = new Busboy({headers: req.headers});
busboy.on('file', function(_, file) {
file.pipe(fs.createWriteStream(__dirname + '/upload'));
});
busboy.on('finish', function() {
res.writeHead(200, {'Connection': 'close'});
res.end("That's all folks!");
});
req.pipe(busboy);
}
}).listen(PORT, function() {
console.info('listening on http://0.0.0.0:' + PORT + '/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment