Last active
August 29, 2015 14:26
-
-
Save silverwind/10f076397348a64a72a5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
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