From 4eaa8325904c3edcd34c8ccdb41a2206dddfd4f4 Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Mon, 16 May 2016 11:42:32 -0400 Subject: [PATCH 1/6] Storage write streams should be able to use a pre-existing uri Closes #1321 --- lib/storage/file.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/storage/file.js b/lib/storage/file.js index ffaf7ebf475..d4d3a96522a 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -1528,7 +1528,7 @@ File.prototype.startResumableUpload_ = function(dup, options) { metadata: {} }, options); - var uploadStream = resumableUpload({ + var config = { authClient: this.storage.authClient, bucket: this.bucket.name, file: this.name, @@ -1537,7 +1537,13 @@ File.prototype.startResumableUpload_ = function(dup, options) { predefinedAcl: options.predefinedAcl, private: options.private, public: options.public - }); + }; + + if (options.uri) { + config.uri = options.uri; + } + + var uploadStream = resumableUpload(config); uploadStream .on('response', function(resp) { From 8df1aa871715564e4e4cc45d9d6da616d6f602fe Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Mon, 16 May 2016 17:01:53 -0400 Subject: [PATCH 2/6] gcs-resumable-upload will ignore the uri if it is falsy --- lib/storage/file.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/storage/file.js b/lib/storage/file.js index d4d3a96522a..23490fac25a 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -1528,7 +1528,7 @@ File.prototype.startResumableUpload_ = function(dup, options) { metadata: {} }, options); - var config = { + var uploadStream = resumableUpload({ authClient: this.storage.authClient, bucket: this.bucket.name, file: this.name, @@ -1536,14 +1536,9 @@ File.prototype.startResumableUpload_ = function(dup, options) { metadata: options.metadata, predefinedAcl: options.predefinedAcl, private: options.private, - public: options.public - }; - - if (options.uri) { - config.uri = options.uri; - } - - var uploadStream = resumableUpload(config); + public: options.public, + uri: options.uri + }); uploadStream .on('response', function(resp) { From 04aeacea915cb7eca136fadb6d982652ac44aea0 Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Mon, 16 May 2016 17:06:12 -0400 Subject: [PATCH 3/6] Add uri parameter to jsdocs --- lib/storage/bucket.js | 2 ++ lib/storage/file.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/storage/bucket.js b/lib/storage/bucket.js index faa8ccf1cf0..66fc0352515 100644 --- a/lib/storage/bucket.js +++ b/lib/storage/bucket.js @@ -973,6 +973,8 @@ Bucket.prototype.makePublic = function(options, callback) { * MD5 checksum for maximum reliability. CRC32c will provide better * performance with less reliability. You may also choose to skip validation * completely, however this is **not recommended**. + * @param {string} options.uri - The URI for an already-created resumable + * upload. See {module:storage/file#createResumableUpload}. * * @example * //- diff --git a/lib/storage/file.js b/lib/storage/file.js index 23490fac25a..73c5bef2fac 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -752,6 +752,8 @@ File.prototype.createResumableUpload = function(options, callback) { * MD5 checksum for maximum reliability. CRC32c will provide better * performance with less reliability. You may also choose to skip validation * completely, however this is **not recommended**. + * @param {string} options.uri - The URI for an already-created resumable + * upload. See {module:storage/file#createResumableUpload}. * * @example * var fs = require('fs'); From 006754c30bafe0620f355aae233b511ea1877fb0 Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Mon, 16 May 2016 17:23:04 -0400 Subject: [PATCH 4/6] Add myself to contributors --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index fe06b1083d4..a387c494c87 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -12,6 +12,7 @@ # Keep the list alphabetically sorted. Anand Suresh +Ben Stahl Brett Bergmann Burcu Dogan Hector Rovira From 0fbd22f3710727013080e3639ac11a2e7a4ef892 Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Tue, 17 May 2016 11:53:55 -0400 Subject: [PATCH 5/6] Bump gcs-resumable-upload package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba281f2c70e..14e48b8bc26 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "ent": "^2.2.0", "extend": "^3.0.0", "gce-images": "^0.2.0", - "gcs-resumable-upload": "^0.5.0", + "gcs-resumable-upload": "^0.6.0", "google-auto-auth": "^0.2.0", "google-proto-files": "^0.1.1", "grpc": "^0.14.1", From 9a6afeb51aa28ff682a22a8f13f6dbfd4b98a53a Mon Sep 17 00:00:00 2001 From: Ben Stahl Date: Tue, 17 May 2016 16:29:10 -0400 Subject: [PATCH 6/6] Ensure a provided uri is passed to gcs-resumable-upload --- test/storage/file.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/storage/file.js b/test/storage/file.js index 541ebd1c8cb..3aa22ffcbba 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -1073,6 +1073,21 @@ describe('File', function() { writable.end('data'); }); + it('should pass through a provided uri', function(done) { + var options = { + uri: 'https://www.googleapis.com/afakeuri' + }; + + var writable = file.createWriteStream(options); + + file.startResumableUpload_ = function(stream, options_) { + assert.deepEqual(options_.uri, options.uri); + done(); + }; + + writable.write('data'); + }); + describe('validation', function() { var data = 'test';