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
Provenance
- Commit
68c57e0- Tree
bdac763- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
f73c3fc
3 files changed+28 added−26 removed
modified:examples/upload/views/upload.haml.html+5 added-5 removed
1234523456778%h1 Upload%form{ method: 'post' } %input{ type: 'file', name: 'image[]' } %input{ type: 'file', name: 'image[]' } %input{ type: 'file', name: 'image[]' }%form{ method: 'post', enctype: 'multipart/form-data' } %input{ type: 'file', name: 'image[0]' } %input{ type: 'file', name: 'image[1]' } %input{ type: 'file', name: 'image[2]' } .panel %input{ type: 'text', name: 'name', value: 'Name' } %input{ type: 'text', name: 'user[name]', value: 'Name' } %input{ type: 'submit', value: 'Upload' }No newline at end of fileNo newline at end of filemodified:examples/upload/app.js+2 added-1 removed
18 unmodified lines19202122232324252627288 unmodified lines18 unmodified lines this.render('upload.haml.html')})
post('/upload', function(){ require('sys').p(this.params) this.redirect('/upload')})
get('/public/*', function(file){ this.sendfile(dirname(__filename) + '/public/' + file)8 unmodified linesmodified:lib/express/core.js+21 added-20 removed
9 unmodified lines10 process.mixin(require('express/plugin'))11 process.mixin(require('express/mime'))12 process.mixin(require('express/dsl'))13 14-var multipart = require('multipart')15-14+var multipart = require('multipart'),15+ File = require('file').File16+ 17 // --- Route18 19 Route = Class({20 196 unmodified lines217 .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