Created
September 4, 2012 12:35
-
-
Save anonymous/3620800 to your computer and use it in GitHub Desktop.
express 3.0 socket.io + bodyparser
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 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