From 89b74b0633e4654ea12a12ca912053fe31b7035a 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 | 8 ++++++-- test/common/util.js | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/common/util.js b/lib/common/util.js index b2bcf41c9499..f56c3ea5a1f7 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 3503a3acfc00..af6fc3c7a340 100644 --- a/regression/storage.js +++ b/regression/storage.js @@ -374,9 +374,12 @@ describe('storage', function() { }); }); - it('should write metadata', function(done) { + it.only('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 b8fd7348c0d9..f681cc5e1aa8 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(); };