Sha256: 325496f63a9299985619102d7005ccd1879ba87e778bf5f9535115d809c361a1

Contents?: true

Size: 863 Bytes

Versions: 17

Compression:

Stored size: 863 Bytes

Contents

/**
 * Module dependencies.
 */

var connect = require('../');
var fs = require('fs');

connect()
  .use(connect.bodyParser({ defer: true }))
  .use(form)
  .use(upload)
  .listen(3000);

function form(req, res, next) {
  if ('GET' !== req.method) return next();
  res.setHeader('Content-Type', 'text/html');
  res.end('<form method="post" enctype="multipart/form-data">'
    + '<input type="file" name="images" multiple="multiple" />'
    + '<input type="submit" value="Upload" />'
    + '</form>');
}

function upload(req, res, next) {
  if ('POST' !== req.method) return next();

  req.form.on('part', function(part){
    // transfer to s3 etc
    console.log('upload %s %s', part.name, part.filename);
    var out = fs.createWriteStream('/tmp/' + part.filename);
    part.pipe(out);
  });

  req.form.on('close', function(){
    res.end('uploaded!');
  });
}

Version data entries

17 entries across 17 versions & 2 rubygems

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