Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -652,18 +654,19 @@ 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({
authClient: this.bucket.storage.authClient,
bucket: this.bucket.name,
file: this.name,
generation: this.generation,
metadata: metadata || {}
metadata: options.metadata,
origin: options.origin
}, callback);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand All @@ -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;
Expand All @@ -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);
});
});

Expand Down