Pass through AWS/S3 specific options

This commit is contained in:
Alex Owen 2019-03-28 08:52:48 +00:00
parent 00092b5129
commit 30e8ee0a09
2 changed files with 49 additions and 21 deletions

View File

@ -147,28 +147,21 @@ exports.upload = function(provider, req, res, options, cb) {
uploadParams.acl = file.acl;
}
// add AWS specific options
// AWS specific options
// See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
if (options.StorageClass) {
uploadParams.StorageClass = options.StorageClass;
}
if (options.CacheControl) {
uploadParams.CacheControl = options.CacheControl;
}
if (options.ServerSideEncryption) {
uploadParams.ServerSideEncryption = options.ServerSideEncryption;
}
if (options.SSEKMSKeyId) {
uploadParams.SSEKMSKeyId = options.SSEKMSKeyId;
}
if (options.SSECustomerAlgorithm) {
uploadParams.SSECustomerAlgorithm = options.SSECustomerAlgorithm;
}
if (options.SSECustomerKey) {
uploadParams.SSECustomerKey = options.SSECustomerKey;
}
if (options.SSECustomerKeyMD5) {
uploadParams.SSECustomerKeyMD5 = options.SSECustomerKeyMD5;
const awsOptionNames = [
'StorageClass',
'CacheControl',
'ServerSideEncryption',
'SSEKMSKeyId',
'SSECustomerAlgorithm',
'SSECustomerKey',
'SSECustomerKeyMD5',
];
for (const awsOption of awsOptionNames) {
if (typeof options[awsOption] !== 'undefined') {
uploadParams[awsOption] = options[awsOption];
}
}
var writer = provider.upload(uploadParams);

View File

@ -54,6 +54,22 @@ function StorageService(options) {
if (options.maxFieldsSize) {
this.maxFieldsSize = options.maxFieldsSize;
}
// AWS specific options
// See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
const awsOptionNames = [
'StorageClass',
'CacheControl',
'ServerSideEncryption',
'SSEKMSKeyId',
'SSECustomerAlgorithm',
'SSECustomerKey',
'SSECustomerKeyMD5',
];
for (const awsOption of awsOptionNames) {
if (typeof options[awsOption] !== 'undefined') {
this[awsOption] = options[awsOption];
}
}
}
function map(obj) {
@ -304,9 +320,28 @@ StorageService.prototype.upload = function(container, req, res, options, cb) {
if (this.maxFieldsSize && !options.maxFieldsSize) {
options.maxFieldsSize = this.maxFieldsSize;
}
// AWS specific options
// See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
const awsOptionNames = [
'StorageClass',
'CacheControl',
'ServerSideEncryption',
'SSEKMSKeyId',
'SSECustomerAlgorithm',
'SSECustomerKey',
'SSECustomerKeyMD5',
];
for (const awsOption of awsOptionNames) {
if (this[awsOption] && !options[awsOption]) {
options[awsOption] = this[awsOption];
}
}
if (typeof container === 'string') {
options.container = container;
}
debug('Upload configured with options %o', options);
handler.upload(this.client, req, res, options, cb);