Skip to content
Myr

Started multi-part upload support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent f73c3fc · Browse files · 3 files+28 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−26 removed

  • other:+28 added−26 removed

3 files+28 added−26 removed

modified:examples/upload/views/upload.haml.html+5 added-5 removed
modified:examples/upload/app.js+2 added-1 removed
modified:lib/express/core.js+21 added-20 removed
9 unmodified lines
10process.mixin(require('express/plugin'))11process.mixin(require('express/mime'))12process.mixin(require('express/dsl'))1314var multipart = require('multipart')1514var multipart = require('multipart'),15 File = require('file').File16 17// --- Route1819Route = Class({20
196 unmodified lines
217 .createServer(function(request, response){218 request.body = ''219 request.setBodyEncoding('binary')220 if (request.headers['content-type'] &&220 request.headers['content-type'].indexOf('application/x-www-form-urlencoded') > -1) {221 // var stream = new multipart.Stream(request)222 // stream.addListener('part', function(part) {223 // part.addListener('body', function(chunk) {224 // var progress = (stream.bytesReceived / stream.bytesTotal * 100).toFixed(2);225 // var mb = (stream.bytesTotal / 1024 / 1024).toFixed(1);226 // 227 // sys.print("Uploading "+mb+"mb ("+progress+"%)\015");228 // 229 // // chunk could be appended to a file if the uploaded file needs to be saved230 // });231 // });232 // stream.addListener('complete', function() {233 // res.sendHeader(200, {'Content-Type': 'text/plain'});234 // res.sendBody('Thanks for playing!');235 // res.finish();236 // sys.puts("\n=> Done");237 // });221 request.headers['content-type'].indexOf('multipart/form-data') !== -1) {222 var stream = new multipart.Stream(request)223 stream.addListener('part', function(part){224 if (part.filename) {225 var file = new File(part.tempfile = '/tmp/express-' + Number(new Date), 'w'),226 part.pos = 0227 part.addListener('body', function(chunk){228 file.write(chunk, part.pos, 'binary')229 part.pos += chunk.length230 })231 part.addListener('complete', function(){232 file.close()233 })234 }235 })236 stream.addListener('complete', function(){237 self.route(request, response)238 })239 } else240 request.addListener('body', function(chunk){ request.body += chunk }),241 request.addListener('complete', function(){ self.route(request, response) })242 })
65 unmodified lines