Skip to content

Commit

Permalink
storage: pass metadata during stream upload
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Feb 2, 2015
1 parent 5284a39 commit d144998
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion regression/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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);
});
});
Expand Down
4 changes: 3 additions & 1 deletion test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit d144998

Please sign in to comment.