Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2012 12:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3620800 to your computer and use it in GitHub Desktop.
Save anonymous/3620800 to your computer and use it in GitHub Desktop.
express 3.0 socket.io + bodyparser
var express = require('express')
, app = express()
, format = require('util').format
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
app.start = app.listen = function(){
return server.listen.apply(server, arguments)
}
app.use(express.bodyParser());
app.get('/', function(req, res){
res.send('<form method="post" enctype="multipart/form-data">'
+ '<p>Title: <input type="text" name="title" /></p>'
+ '<p>Image: <input type="file" name="image" /></p>'
+ '<p><input type="submit" value="Upload" /></p>'
+ '</form>');
});
app.post('/', function(req, res, next){
// the uploaded file can be found as `req.files.image` and the
// title field as `req.body.title`
res.send(format('\nuploaded %s (%d Kb) to %s as %s'
, req.files.image.name
, req.files.image.size / 1024 | 0
, req.files.image.path
, req.body.title));
});
app.start(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment