Skip to content

Instantly share code, notes, and snippets.

@lakshaygupta21
Created April 18, 2021 14:52
Show Gist options
  • Save lakshaygupta21/a7ca8d1399f9f297038c373350d278e1 to your computer and use it in GitHub Desktop.
Save lakshaygupta21/a7ca8d1399f9f297038c373350d278e1 to your computer and use it in GitHub Desktop.
import AWS from 'aws-sdk'
import S3 from 'react-aws-s3';
const path = require("path")
const S3Encode = require("s3encode").default
const S3_BUCKET = process.env.REACT_APP_BUCKET_NAME;
const REGION = process.env.REACT_APP_AWS_S3_REGION;
AWS.config.update({
accessKeyId: process.env.REACT_APP_AWS_ACCESS_KEY,
secretAccessKey: process.env.REACT_APP_AWS_SECRET_KEY
})
const myBucket = new AWS.S3({
params: {
Bucket: S3_BUCKET
},
region: REGION,
})
export const uploadToS3 = async (file, child, acl) => {
const params = {
ACL: acl ? acl : "authenticated-read",
Body: file,
Bucket: S3_BUCKET,
Key: child,
ContentType: file.type
};
const res = await myBucket.upload(params).promise();
return res.Location ? res.Location : null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment