diff --git a/README.md b/README.md index c3e1151..eb4e21f 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,13 @@ Useful when deploying applications to [fake-s3](https://github.com/jubos/fake-s3 *Default:* `0` +### metadata + +Metadata to be sent with the files. This should be an object that will be passed directly to the `Metadata` key in the `putObject` call of the AWS S3 SDK. Keys will be automatically prefixed with `x-amz-meta-` by the AWS SDK. Note that the AWS SDK treats all metadata values as strings. You should typecast your values to strings for explicit control. + +*Example value*: `{ 'release-id': process.env.RELEASE_ID }` + +*Default:* `null` ### signatureVersion diff --git a/index.js b/index.js index 2a3b574..ffe573c 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ module.exports = { expires: EXPIRE_IN_2030, dotFolders: false, batchSize: 0, + metadata: null, defaultMimeType: 'application/octet-stream', distDir: function(context) { return context.distDir; @@ -68,6 +69,7 @@ module.exports = { var dotFolders = this.readConfig('dotFolders'); var serverSideEncryption = this.readConfig('serverSideEncryption'); var batchSize = this.readConfig('batchSize'); + var metadata = this.readConfig('metadata'); var defaultMimeType = this.readConfig('defaultMimeType'); var filesToUpload = distFiles.filter(minimatch.filter(filePattern, { matchBase: true, dot: dotFolders })); @@ -98,6 +100,7 @@ module.exports = { cacheControl: cacheControl, expires: expires, batchSize: batchSize, + metadata: metadata, defaultMimeType: defaultMimeType }; diff --git a/lib/s3.js b/lib/s3.js index d11c3d4..b6ec27c 100644 --- a/lib/s3.js +++ b/lib/s3.js @@ -141,6 +141,7 @@ module.exports = CoreObject.extend({ var brotliCompressedFilePaths = options.brotliCompressedFilePaths || []; var cacheControl = options.cacheControl; var expires = options.expires; + var metadata = options.metadata; var serverSideEncryption = options.serverSideEncryption; var defaultType = options.defaultMimeType || mime.getType('bin'); @@ -187,6 +188,10 @@ module.exports = CoreObject.extend({ params.ServerSideEncryption = serverSideEncryption; } + if (metadata) { + params.Metadata = metadata; + } + if (isGzipped) { params.ContentEncoding = 'gzip'; } diff --git a/tests/index-test.js b/tests/index-test.js index e89e37d..d9d8b5b 100644 --- a/tests/index-test.js +++ b/tests/index-test.js @@ -131,7 +131,7 @@ describe('s3 plugin', function() { return previous; }, []); - assert.equal(messages.length, 8); + assert.equal(messages.length, 9); }); describe('required config', function() { diff --git a/tests/lib/s3-test.js b/tests/lib/s3-test.js index b453adf..e279c1d 100644 --- a/tests/lib/s3-test.js +++ b/tests/lib/s3-test.js @@ -149,6 +149,26 @@ describe('s3', function() { }); }); + it('sets Metadata using metadata', function() { + var s3Params; + s3Client.putObject = function(params, cb) { + s3Params = params; + cb(); + }; + + var options = { + filePaths: ['app.css'], + cwd: process.cwd() + '/tests/fixtures/dist', + prefix: 'js-app', + metadata: { 'test-key': 'test-value' } + }; + + return assert.isFulfilled(subject.upload(options)) + .then(function() { + assert.deepEqual(s3Params.Metadata, { 'test-key': 'test-value' }); + }); + }); + it('sends the correct content type params for gzipped files with .gz extension', function() { var s3Params; s3Client.putObject = function(params, cb) {