Skip to content
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 }));
Expand Down Expand Up @@ -98,6 +100,7 @@ module.exports = {
cacheControl: cacheControl,
expires: expires,
batchSize: batchSize,
metadata: metadata,
defaultMimeType: defaultMimeType
};

Expand Down
5 changes: 5 additions & 0 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -187,6 +188,10 @@ module.exports = CoreObject.extend({
params.ServerSideEncryption = serverSideEncryption;
}

if (metadata) {
params.Metadata = metadata;
}

if (isGzipped) {
params.ContentEncoding = 'gzip';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('s3 plugin', function() {
return previous;
}, []);

assert.equal(messages.length, 8);
assert.equal(messages.length, 9);
});

describe('required config', function() {
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/s3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down