diff --git a/lib/storage/file.js b/lib/storage/file.js index e01ab58662a..323e0f38abf 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -640,7 +640,9 @@ File.prototype.createReadStream = function(options) { * * @resource [Resumable upload guide]{@link https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable} * - * @param {object=} metadata - Optional metadata to set on the file. + * @param {object=} options - Configuration object. + * @param {object} options.metadata - Metadata to set on the file. + * @param {string} options.origin - Origin header to set for the upload. * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request * @param {string} callback.uri - The resumable upload's unique session URI. @@ -652,10 +654,10 @@ File.prototype.createReadStream = function(options) { * } * }); */ -File.prototype.createResumableUpload = function(metadata, callback) { - if (is.fn(metadata)) { - callback = metadata; - metadata = {}; +File.prototype.createResumableUpload = function(options, callback) { + if (is.fn(options)) { + callback = options; + options = {}; } resumableUpload.createURI({ @@ -663,7 +665,8 @@ File.prototype.createResumableUpload = function(metadata, callback) { bucket: this.bucket.name, file: this.name, generation: this.generation, - metadata: metadata || {} + metadata: options.metadata, + origin: options.origin }, callback); }; diff --git a/package.json b/package.json index d293f92f303..306d3214de0 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "duplexify": "^3.2.0", "extend": "^3.0.0", "gce-images": "^0.2.0", - "gcs-resumable-upload": "^0.3.0", + "gcs-resumable-upload": "^0.4.0", "google-auto-auth": "^0.2.0", "hash-stream-validation": "^0.1.0", "is": "^3.0.1", diff --git a/test/storage/file.js b/test/storage/file.js index 9e682c924bc..54103ba11d8 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -877,10 +877,10 @@ describe('File', function() { }); describe('createResumableUpload', function() { - it('should not require metadata', function(done) { + it('should not require options', function(done) { resumableUploadOverride = { createURI: function(opts, callback) { - assert.deepEqual(opts.metadata, {}); + assert.strictEqual(opts.metadata, undefined); callback(); } }; @@ -889,8 +889,11 @@ describe('File', function() { }); it('should create a resumable upload URI', function(done) { - var metadata = { - contentType: 'application/json' + var options = { + metadata: { + contentType: 'application/json' + }, + origin: '*' }; file.generation = 3; @@ -905,13 +908,14 @@ describe('File', function() { assert.strictEqual(opts.bucket, bucket.name); assert.strictEqual(opts.file, file.name); assert.strictEqual(opts.generation, file.generation); - assert.strictEqual(opts.metadata, metadata); + assert.strictEqual(opts.metadata, options.metadata); + assert.strictEqual(opts.origin, options.origin); callback(); } }; - file.createResumableUpload(metadata, done); + file.createResumableUpload(options, done); }); });