Skip to content

Instantly share code, notes, and snippets.

@RobsonX4
Last active July 7, 2020 15:50
Show Gist options
  • Select an option

  • Save RobsonX4/b394d3411d596e8563fe64a1d29fd966 to your computer and use it in GitHub Desktop.

Select an option

Save RobsonX4/b394d3411d596e8563fe64a1d29fd966 to your computer and use it in GitHub Desktop.
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