Created
August 13, 2020 16:38
-
-
Save bismitaguha/176b09fb38494c7ef9fa7fc9a0b008c2 to your computer and use it in GitHub Desktop.
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
uploadFile = (file) => { | |
AWS.config.update({ | |
region: 'ap-south-1', | |
accessKeyId: process.env.REACT_APP_AWSAccessKeyId, | |
secretAccessKey: process.env.REACT_APP_AWSSecretKey, | |
}) | |
const send_file = file | |
file = file.split('.') | |
const params = { | |
ACL: 'public-read', | |
Key: file[0], | |
ContentType: 'application/octet-stream', | |
Body: send_file, | |
Bucket: process.env.REACT_APP_Bucket | |
} | |
var myBucket = new AWS.S3() | |
myBucket.putObject(params) | |
.on('httpUploadProgress', (evt) => { | |
this.setState({ | |
url: `https://${process.env.REACT_APP_Bucket}.s3.amazonaws.com/${file[0]}` | |
}) | |
}) | |
.send((err) => { | |
if (err) { | |
console.log(err) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment