Skip to content

Commit

Permalink
feat: allow for additional params on conditionalPut
Browse files Browse the repository at this point in the history
When you add params like `ContentType` to your conditionalPut, those
were being sent to the GetObject call as well. Now we filter the params
sent to the GetObject call so that no unsupported params are sent to it.
  • Loading branch information
jthomerson committed Jun 17, 2020
1 parent 0c6f202 commit ddaf4af
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions getFileBody.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
'use strict';

var Q = require('q'),
_ = require('underscore'),
AWS = require('aws-sdk'),
s3 = new AWS.S3();
s3 = new AWS.S3(),
RETAINED_KEYS;

RETAINED_KEYS = [
'Bucket',
'Key',
'IfMatch',
'IfModifiedSince',
'IfNoneMatch',
'IfUnmodifiedSince',
'PartNumber',
'Range',
'RequestPayer',
'ResponseCacheControl',
'ResponseContentDisposition',
'ResponseContentEncoding',
'ResponseContentLanguage',
'ResponseContentType',
'ResponseExpires',
'SSECustomerAlgorithm',
'SSECustomerKey',
'SSECustomerKeyMD5',
'VersionId',
];

/**
* Returns false if a file did not exist, otherwise returns the string or
Expand All @@ -13,7 +37,7 @@ var Q = require('q'),
* not exist
*/
module.exports = function getExistingFileBody(params) {
return Q.ninvoke(s3, 'getObject', params)
return Q.ninvoke(s3, 'getObject', _.pick(params, RETAINED_KEYS))
.then(function(resp) {
return resp.Body;
})
Expand Down

0 comments on commit ddaf4af

Please sign in to comment.