From d1449980418da33346037965bd6042909d74162a Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 2 Feb 2015 12:00:27 -0500 Subject: [PATCH] storage: pass metadata during stream upload --- lib/common/util.js | 4 +++- regression/storage.js | 6 +++++- test/common/util.js | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/common/util.js b/lib/common/util.js index b2bcf41c949..f56c3ea5a1f 100644 --- a/lib/common/util.js +++ b/lib/common/util.js @@ -304,7 +304,9 @@ function makeWritableStream(dup, options, onComplete) { // Write the metadata to the request. stream.write('--' + boundary + '\n'); stream.write('Content-Type: application/json\n\n'); - stream.write(JSON.stringify(options.metadata)); + stream.write(JSON.stringify({ + metadata: options.metadata + })); stream.write('\n\n'); stream.write('--' + boundary + '\n'); stream.write('Content-Type: ' + streamType + '\n\n'); diff --git a/regression/storage.js b/regression/storage.js index 3503a3acfc0..18628c927a9 100644 --- a/regression/storage.js +++ b/regression/storage.js @@ -376,7 +376,10 @@ describe('storage', function() { it('should write metadata', function(done) { var options = { - metadata: { contentType: 'image/png' }, + metadata: { + contentType: 'image/png', + property: 'value' + }, resumable: false }; @@ -386,6 +389,7 @@ describe('storage', function() { file.getMetadata(function(err, metadata) { assert.ifError(err); assert.equal(metadata.contentType, options.metadata.contentType); + assert.equal(metadata.metadata.property, options.metadata.property); file.delete(done); }); }); diff --git a/test/common/util.js b/test/common/util.js index b8fd7348c0d..f681cc5e1aa 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -210,7 +210,9 @@ describe('common/util', function() { assert(endFirstBoundaryIdx > startFirstBoundaryIdx); assert(endBoundaryIdx > -1); - assert(written.indexOf(JSON.stringify(metadata)) > -1); + assert(written.indexOf(JSON.stringify({ + metadata: metadata + })) > -1); done(); };