Skip to content

Instantly share code, notes, and snippets.

@bismitaguha
Created August 13, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bismitaguha/176b09fb38494c7ef9fa7fc9a0b008c2 to your computer and use it in GitHub Desktop.
Save bismitaguha/176b09fb38494c7ef9fa7fc9a0b008c2 to your computer and use it in GitHub Desktop.
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