Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[implements ACL and S3 response] Add Access Control List option #66

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ req.file('avatar')
secret: 'AB2g1939eaGAdesoccertournament',
bucket: 'my_stuff',
// Optional
token: 'temporary_sts_creds'
token: 'temporary_sts_creds',
ACL: 'file_permission'
}, function whenDone(err, uploadedFiles) {
if (err) {
return res.serverError(err);
Expand Down
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ module.exports = function SkipperS3 (globalOpts) {

return {

/**
* @param {String} operation: 'getObject' || 'putObject'
*
* @param {Dictionary}
* @property {String} Key
* @property {String} Bucket
* @property {Number} Expires - seconds
* @example { Key: '53429b94853c4efb70740eef/3228796d-fe9b-4762-991e-db0d379fedab.jpg', Bucket: 'my-content'}
*
* @returns String
*
* @docs -> https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
*/
url: function (operation, params, done) {
_buildS3Client(globalOpts).getSignedUrl(operation, params, done);
},

read: function (fd) {
if (arguments[1]) {
return arguments[1](new Error('For performance reasons, skipper-s3 does not support passing in a callback to `.read()`'));
Expand Down Expand Up @@ -206,6 +223,7 @@ function _buildS3Client(s3ClientOpts) {
region: s3ClientOpts.region,
accessKeyId: s3ClientOpts.key,
secretAccessKey: s3ClientOpts.secret,
ACL: s3ClientOpts.ACL,
endpoint: s3ClientOpts.endpoint
});
return new AWS.S3(s3ConstructorArgins);
Expand All @@ -217,12 +235,14 @@ function _uploadFile(incomingFd, incomingFileStream, handleProgress, s3ClientOpt
.upload(_stripKeysWithUndefinedValues({
Bucket: s3ClientOpts.bucket,
Key: incomingFd.replace(/^\/+/, ''),//芦 remove any leading slashes
ACL: s3ClientOpts.ACL,
Body: incomingFileStream,
ContentType: mime.getType(incomingFd)//芦 advisory; makes things nicer in the S3 dashboard
}), (err, rawS3ResponseData)=>{
if (err) {
return done(err);
} else {
incomingFileStream.extra = rawS3ResponseData;
return done(undefined, {
rawS3ResponseData
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skipper-s3",
"version": "0.6.0",
"version": "0.6.2",
"description": "Stream file uploads, downloads, and transloads to and from S3. Plus some other utilities like `rm` and `ls`.",
"main": "index.js",
"scripts": {
Expand Down