-
-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add S3 support for uploads (#938)
- Loading branch information
1 parent
f6ea10d
commit 950a070
Showing
16 changed files
with
579 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
server/api/helpers/utils/get-simple-storage-service-client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const AWS = require('aws-sdk'); | ||
|
||
class S3Client { | ||
constructor(options) { | ||
AWS.config.update({ | ||
accessKeyId: options.accessKeyId, | ||
secretAccessKey: options.secretAccessKey, | ||
region: options.region, | ||
}); | ||
this.bucket = options.bucket; | ||
this.client = new AWS.S3({ | ||
endpoint: options.endpoint, | ||
}); | ||
} | ||
|
||
upload({ Key, Body, ContentType }) { | ||
return this.client | ||
.upload({ | ||
Bucket: this.bucket, | ||
Key, | ||
Body, | ||
ContentType, | ||
ACL: 'public-read', | ||
}) | ||
.promise(); | ||
} | ||
|
||
delete({ Key }) { | ||
return this.client | ||
.deleteObject({ | ||
Bucket: this.bucket, | ||
Key, | ||
}) | ||
.promise(); | ||
} | ||
} | ||
|
||
module.exports = { | ||
fn() { | ||
if (sails.config.custom.s3Config) { | ||
return new S3Client(sails.config.custom.s3Config); | ||
} | ||
return null; | ||
}, | ||
}; |
Oops, something went wrong.