Sha256: 56a840392c814270eccbe8cd58e20efb9d43e3903ee414fc6a2df43eebc469b9
Contents?: true
Size: 989 Bytes
Versions: 17
Compression:
Stored size: 989 Bytes
Contents
var connect = require('../') , http = require('http'); // visit form.html var app = connect() .use(connect.static(__dirname + '/public')) .use(connect.limit('5mb')) .use(connect.bodyParser()) .use(form) .use(upload); function form(req, res, next){ if ('GET' != req.method) return next(); res.statusCode = 302; res.setHeader('Location', 'form.html'); res.end(); } function upload(req, res){ res.setHeader('Content-Type', 'text/html'); res.write('<p>thanks ' + req.body.name + '</p>'); res.write('<ul>'); if (Array.isArray(req.files.images)) { req.files.images.forEach(function(image){ var kb = image.size / 1024 | 0; res.write('<li>uploaded ' + image.name + ' ' + kb + 'kb</li>'); }); } else { var image = req.files.images; var kb = image.size / 1024 | 0; res.write('<li>uploaded ' + image.name + ' ' + kb + 'kb</li>'); } res.end('</ul>'); } http.Server(app).listen(3000); console.log('Server started on port 3000');
Version data entries
17 entries across 17 versions & 2 rubygems