Skip to content

Commit 76ade4d

Browse files
committed
Merge pull request #1100 from stephenplusplus/spp--1099
storage: allow setting an origin for a resumable upload URI
2 parents f69d6ec + 9202574 commit 76ade4d

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

lib/storage/file.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ File.prototype.createReadStream = function(options) {
640640
*
641641
* @resource [Resumable upload guide]{@link https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable}
642642
*
643-
* @param {object=} metadata - Optional metadata to set on the file.
643+
* @param {object=} options - Configuration object.
644+
* @param {object} options.metadata - Metadata to set on the file.
645+
* @param {string} options.origin - Origin header to set for the upload.
644646
* @param {function} callback - The callback function.
645647
* @param {?error} callback.err - An error returned while making this request
646648
* @param {string} callback.uri - The resumable upload's unique session URI.
@@ -652,18 +654,19 @@ File.prototype.createReadStream = function(options) {
652654
* }
653655
* });
654656
*/
655-
File.prototype.createResumableUpload = function(metadata, callback) {
656-
if (is.fn(metadata)) {
657-
callback = metadata;
658-
metadata = {};
657+
File.prototype.createResumableUpload = function(options, callback) {
658+
if (is.fn(options)) {
659+
callback = options;
660+
options = {};
659661
}
660662

661663
resumableUpload.createURI({
662664
authClient: this.bucket.storage.authClient,
663665
bucket: this.bucket.name,
664666
file: this.name,
665667
generation: this.generation,
666-
metadata: metadata || {}
668+
metadata: options.metadata,
669+
origin: options.origin
667670
}, callback);
668671
};
669672

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"duplexify": "^3.2.0",
9393
"extend": "^3.0.0",
9494
"gce-images": "^0.2.0",
95-
"gcs-resumable-upload": "^0.3.0",
95+
"gcs-resumable-upload": "^0.4.0",
9696
"google-auto-auth": "^0.2.0",
9797
"hash-stream-validation": "^0.1.0",
9898
"is": "^3.0.1",

test/storage/file.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,10 @@ describe('File', function() {
877877
});
878878

879879
describe('createResumableUpload', function() {
880-
it('should not require metadata', function(done) {
880+
it('should not require options', function(done) {
881881
resumableUploadOverride = {
882882
createURI: function(opts, callback) {
883-
assert.deepEqual(opts.metadata, {});
883+
assert.strictEqual(opts.metadata, undefined);
884884
callback();
885885
}
886886
};
@@ -889,8 +889,11 @@ describe('File', function() {
889889
});
890890

891891
it('should create a resumable upload URI', function(done) {
892-
var metadata = {
893-
contentType: 'application/json'
892+
var options = {
893+
metadata: {
894+
contentType: 'application/json'
895+
},
896+
origin: '*'
894897
};
895898

896899
file.generation = 3;
@@ -905,13 +908,14 @@ describe('File', function() {
905908
assert.strictEqual(opts.bucket, bucket.name);
906909
assert.strictEqual(opts.file, file.name);
907910
assert.strictEqual(opts.generation, file.generation);
908-
assert.strictEqual(opts.metadata, metadata);
911+
assert.strictEqual(opts.metadata, options.metadata);
912+
assert.strictEqual(opts.origin, options.origin);
909913

910914
callback();
911915
}
912916
};
913917

914-
file.createResumableUpload(metadata, done);
918+
file.createResumableUpload(options, done);
915919
});
916920
});
917921

0 commit comments

Comments
 (0)