Last active
July 7, 2020 15:50
-
-
Save RobsonX4/b394d3411d596e8563fe64a1d29fd966 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const AWS = require('aws-sdk'); | |
| class AWSS3Service { | |
| /** | |
| * Get new S3 Instance | |
| */ | |
| getS3Instance() { | |
| return new AWS.S3({ | |
| accessKeyId: "YOUR_AWS_ACCESS_KEY", | |
| secretAccessKey: "YOUR_AWS_SECRET_ACCESS_KEY" | |
| }); | |
| } | |
| /** | |
| * Upload new file | |
| * @param {*} bucketName | |
| * @param {*} access | |
| * @param {*} file | |
| * @param {*} fileName | |
| */ | |
| async uploadFile(bucketName, access = 'private', file, fileName) { | |
| const s3 = this.getS3Instance(); | |
| const params = { | |
| Bucket: bucketName, | |
| ACL: access, | |
| Key: fileName, | |
| Body: file | |
| }; | |
| return await s3.upload(params).promise(); | |
| } | |
| /** | |
| * Get file | |
| * @param {*} bucket | |
| * @param {*} fileName | |
| */ | |
| async getFile(bucket, fileName) { | |
| const s3 = this.getS3Instance(); | |
| const params = { Bucket: bucket, Key: fileName }; | |
| return await s3.getObject(params).promise(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment