index.js
This file
Path
examples/multipart/index.js
60 lines · 1.4 KiB · JavaScript
Last changed by
Fix typo in console.log in multipart exampleJoshua Goldbergbefore adoptionad05eb8
History of this fileTake it
The walk stopped after 200 commits: lines older than 2e68ddb point at it.
expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
lines 1–4why, one step back1/**2 * Module dependencies.3 */4Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 5why, one step back5var express = require('../..');Merge pull request #2018 from Devrama/patch-1Jonathan Ongbefore adoption412eb2a
line 6why, one step back6var multiparty = require('multiparty');Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 7why, one step back7var format = require('util').format;expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
line 8why, one step back8Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 9why, one step back9var app = module.exports = express();expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
lines 10–19why, one step back1011app.get('/', function(req, res){12 res.send('<form method="post" enctype="multipart/form-data">'13 + '<p>Title: <input type="text" name="title" /></p>'14 + '<p>Image: <input type="file" name="image" /></p>'15 + '<p><input type="submit" value="Upload" /></p>'16 + '</form>');17});1819app.post('/', function(req, res, next){fix multipart exampleDouglas Christopher Wilsonbefore adoption374e6c3
lines 20–53why, one step back20 // create a form to begin parsing21 var form = new multiparty.Form();22 var image;23 var title;2425 form.on('error', next);26 form.on('close', function(){27 res.send(format('\nuploaded %s (%d Kb) as %s'28 , image.filename29 , image.size / 1024 | 030 , title));31 });3233 // listen on field event for title34 form.on('field', function(name, val){35 if (name !== 'title') return;36 title = val;37 });3839 // listen on part event for image file40 form.on('part', function(part){41 if (!part.filename) return;42 if (part.name !== 'image') return part.resume();43 image = {};44 image.filename = part.filename;45 image.size = 0;46 part.on('data', function(buf){47 image.size += buf.length;48 });49 });505152 // parse the form53 form.parse(req);expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
lines 54–55why, one step back54});55Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
line 56why, one step back56/* istanbul ignore next */expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
line 57why, one step back57if (!module.parent) {fix multipart exampleDouglas Christopher Wilsonbefore adoption374e6c3
line 58why, one step back58 app.listen(4000);Fix typo in console.log in multipart exampleJoshua Goldbergbefore adoptionad05eb8
line 59why, one step back59 console.log('Express started on port 4000');expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb
line 60why, one step back60}