Added multi-part upload support. Closes #155
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 12bc374 · Browse files · 5 files·+34 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+34 added−9 removed
- other:+34 added−9 removed
Provenance
- Commit
5fe35bf- Tree
5566960- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
12bc374
5 files changed+34 added−9 removed
modified:examples/upload/views/upload.haml.html+3 added-3 removed
12345345678%h1 Upload%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]' } %input{ type: 'file', name: 'images[0]' } %input{ type: 'file', name: 'images[1]' } %input{ type: 'file', name: 'images[2]' } .panel %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-1 removed
18 unmodified lines1920212223232425269 unmodified lines18 unmodified lines this.render('upload.haml.html')})
post('/upload', function(){ require('sys').p(this.params) this.redirect('/upload')})
get('/public/*', function(file){9 unmodified linesmodified:lib/express/core.js+1 added
228 unmodified lines229 part.pos += chunk.length230 })231 part.addListener('complete', function(){232 file.close()233+ request.params = { post: mergeParam(part.name, part, {}) }234 })235 }236 })237 stream.addListener('complete', function(){71 unmodified linesmodified:lib/express/helpers.js+26 added
90 unmodified lines91929394959697989910010110210310410510610710810911011111211311411511611711811912012190 unmodified lines
exports.escapeRegexp = function(string, chars) { var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\') return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')}
/** * Merge param _key_ and _val_ into _params_. Key * should be a query string key such as 'user[name]', * and _val_ is it's associated value. The root _params_ * object is returned. * * This is primarily used by Express for merging multi-part * body values together. * * @param {string} key * @param {string} val * @return {hash} * @api public */
exports.mergeParam = function(key, val, params) { var keys = key.match(/^(\w+)(?:\[(\w+)\])*/), orig = params for (var i = 1, len = keys.length; i < len; ++i) if (i == len - 1) params[keys[i]] = val else params = (params[keys[i]] = params[keys[i]] || {}) return orig}No newline at end of fileNo newline at end of filemodified:lib/express/request.js+4 added-5 removed
65 unmodified lines66 response.headers = {}67 this.response = response68 this.url = url.parse(this.url)69 this.url.pathname = exports.normalizePath(this.url.pathname)70- this.params = { 71- get: this.url.query ? queryString.parseQuery(this.url.query) : {}, 72- post: {}, 73- path: {}74- }70+ this.params = this.params || {}71+ this.params.path = {}72+ this.params.get = this.url.query ? queryString.parseQuery(this.url.query) : {}73+ this.params.post = this.params.post || {}74 this.plugins = $(Express.plugins).map(function(plugin){75 return new plugin.klass(plugin.options) 76 })77 },186 unmodified lines