Skip to content
Myr

Fixed incomplete file upload issue. Closes #167

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

Route now waits until all files have been written / closed until executing

authored by visionmedia · committed by visionmedia · parent 0186659 · Browse files · 1 file+16 added−4 removed
This commit

State

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

Diff stats

1 file+16 added−4 removed

  • other:+16 added−4 removed

1 file+16 added−4 removed

modified:lib/express/core.js+16 added-4 removed
217 unmodified lines
218 request.body = ''219 request.setBodyEncoding('binary')220 if (request.headers['content-type'] &&221 request.headers['content-type'].indexOf('multipart/form-data') !== -1) {222 var stream = new multipart.Stream(request)222 var stream = new multipart.Stream(request),223 promise = new process.Promise,224 pendingFiles = 0225 request.params = { post: {}}226 stream.addListener('part', function(part){227 if (part.filename) {228 var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + uid(), 'w')229 ++pendingFiles230 part.pos = 0231 part.addListener('body', function(chunk){229 file.write(chunk, part.pos, 'binary')232 file.write(chunk, part.pos, 'binary').addErrback(function(){233 promise.emitError.apply(promise, arguments)234 })235 part.pos += chunk.length236 })237 part.addListener('complete', function(){233 file.close()238 file.close().addCallback(function(){239 if (!--pendingFiles)240 promise.emitSuccess()241 }).addErrback(function(){242 promise.emitError.apply(promise, arguments)243 })244 mergeParam(part.name, part, request.params.post)245 })246 }247 else
3 unmodified lines
251 .addListener('complete', function(){252 if (part.buf.length)253 mergeParam(part.name, part.buf, request.params.post)254 })245 }).addListener('complete', function(){ self.route(request, response) })255 }).addListener('complete', function(){256 promise.addCallback(function(){ self.route(request, response) })257 })258 }259 else260 request261 .addListener('body', function(chunk){ request.body += chunk })
67 unmodified lines