Created
December 5, 2020 17:56
-
-
Save basyusuf/53739ed91361234b641ae81a3d010d5f to your computer and use it in GitHub Desktop.
Helper Func S3
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 putObjectToS3 = async(key, data) => { | |
console.info("Starting PutObject S3"); | |
let s3Bucket = new AWS.S3(); | |
let params = { | |
Bucket: BUCKET_NAME, | |
Key: key, | |
Body: data, | |
ContentEncoding: 'base64', | |
ContentType: 'image/jpeg', | |
ACL: 'public-read' | |
} | |
console.info("S3 Parameters: ", params); | |
return await new Promise((resolve, reject) => { | |
s3Bucket.putObject(params, (err, data) => { | |
if (err) { | |
console.info("S3 PutObject Error:", err, err.stack); | |
reject(error); | |
} | |
else { | |
console.info("S3 PutObject successfull. Information:", data); | |
resolve(data); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment