Skip to content

Instantly share code, notes, and snippets.

@silverwind
Last active August 29, 2015 14:26
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 silverwind/10f076397348a64a72a5 to your computer and use it in GitHub Desktop.
Save silverwind/10f076397348a64a72a5 to your computer and use it in GitHub Desktop.
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