mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
parent
2a89eb5c74
commit
3abea7f818
|
|
@ -13,7 +13,6 @@ This page contains list of examples using Express.
|
||||||
- [hello-world](./hello-world) - Simple request handler
|
- [hello-world](./hello-world) - Simple request handler
|
||||||
- [markdown](./markdown) - Markdown as template engine
|
- [markdown](./markdown) - Markdown as template engine
|
||||||
- [multi-router](./multi-router) - Working with multiple Express routers
|
- [multi-router](./multi-router) - Working with multiple Express routers
|
||||||
- [multipart](./multipart) - Accepting multipart-encoded forms
|
|
||||||
- [mvc](./mvc) - MVC-style controllers
|
- [mvc](./mvc) - MVC-style controllers
|
||||||
- [online](./online) - Tracking online user activity with `online` and `redis` packages
|
- [online](./online) - Tracking online user activity with `online` and `redis` packages
|
||||||
- [params](./params) - Working with route parameters
|
- [params](./params) - Working with route parameters
|
||||||
|
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var express = require('../..');
|
|
||||||
var multiparty = require('multiparty');
|
|
||||||
var format = require('util').format;
|
|
||||||
|
|
||||||
var app = module.exports = express();
|
|
||||||
|
|
||||||
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){
|
|
||||||
// create a form to begin parsing
|
|
||||||
var form = new multiparty.Form();
|
|
||||||
var image;
|
|
||||||
var title;
|
|
||||||
|
|
||||||
form.on('error', next);
|
|
||||||
form.on('close', function(){
|
|
||||||
res.send(format('\nuploaded %s (%d Kb) as %s'
|
|
||||||
, image.filename
|
|
||||||
, image.size / 1024 | 0
|
|
||||||
, title));
|
|
||||||
});
|
|
||||||
|
|
||||||
// listen on field event for title
|
|
||||||
form.on('field', function(name, val){
|
|
||||||
if (name !== 'title') return;
|
|
||||||
title = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
// listen on part event for image file
|
|
||||||
form.on('part', function(part){
|
|
||||||
if (!part.filename) return;
|
|
||||||
if (part.name !== 'image') return part.resume();
|
|
||||||
image = {};
|
|
||||||
image.filename = part.filename;
|
|
||||||
image.size = 0;
|
|
||||||
part.on('data', function(buf){
|
|
||||||
image.size += buf.length;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// parse the form
|
|
||||||
form.parse(req);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (!module.parent) {
|
|
||||||
app.listen(4000);
|
|
||||||
console.log('Express started on port 4000');
|
|
||||||
}
|
|
||||||
|
|
@ -73,7 +73,6 @@
|
||||||
"method-override": "3.0.0",
|
"method-override": "3.0.0",
|
||||||
"mocha": "10.2.0",
|
"mocha": "10.2.0",
|
||||||
"morgan": "1.10.0",
|
"morgan": "1.10.0",
|
||||||
"multiparty": "4.2.3",
|
|
||||||
"nyc": "15.1.0",
|
"nyc": "15.1.0",
|
||||||
"pbkdf2-password": "1.2.1",
|
"pbkdf2-password": "1.2.1",
|
||||||
"supertest": "6.3.0",
|
"supertest": "6.3.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user