diff --git a/lib/storage/file.js b/lib/storage/file.js index 211af929960..8d727ce9a03 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -159,9 +159,9 @@ File.prototype.copy = function(destination, callback) { throw noDestinationError; } var path = util.format('/o/{srcName}/copyTo/b/{destBucket}/o/{destName}', { - srcName: this.name, + srcName: encodeURIComponent(this.name), destBucket: destBucket.name, - destName: destName + destName: encodeURIComponent(destName) }); this.makeReq_('POST', path, null, {}, function(err) { if (err) { @@ -272,7 +272,7 @@ File.prototype.createWriteStream = function(metadata) { metadata: metadata, request: { qs: { - name: that.name, + name: that.name }, uri: util.format('{base}/{bucket}/o', { base: STORAGE_UPLOAD_BASE_URL, @@ -300,7 +300,8 @@ File.prototype.createWriteStream = function(metadata) { */ File.prototype.delete = function(callback) { callback = callback || util.noop; - this.makeReq_('DELETE', '/o/' + this.name, null, true, function(err) { + var path = '/o/' + encodeURIComponent(this.name); + this.makeReq_('DELETE', path, null, true, function(err) { if (err) { callback(err); return; @@ -319,7 +320,8 @@ File.prototype.delete = function(callback) { */ File.prototype.getMetadata = function(callback) { callback = callback || util.noop; - this.makeReq_('GET', '/o/' + this.name, null, true, function(err, resp) { + var path = '/o/' + encodeURIComponent(this.name); + this.makeReq_('GET', path, null, true, function(err, resp) { if (err) { callback(err); return; @@ -365,7 +367,9 @@ File.prototype.getSignedUrl = function(options, callback) { delete: 'DELETE' }[options.action]; - options.resource = '/' + this.bucket.name + '/' + this.name; + var name = encodeURIComponent(this.name); + + options.resource = '/' + this.bucket.name + '/' + name; var makeAuthorizedRequest_ = this.bucket.storage.makeAuthorizedRequest_; @@ -411,8 +415,8 @@ File.prototype.getSignedUrl = function(options, callback) { */ File.prototype.setMetadata = function(metadata, callback) { callback = callback || util.noop; - this.makeReq_( - 'PATCH', '/o/' + this.name, null, metadata, function(err, resp) { + var path = '/o/' + encodeURIComponent(this.name); + this.makeReq_('PATCH', path, null, metadata, function(err, resp) { if (err) { callback(err); return;