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

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/examples/limit.js