Skip to content

Instantly share code, notes, and snippets.

@basyusuf
Created December 5, 2020 17:56
Show Gist options
  • Save basyusuf/53739ed91361234b641ae81a3d010d5f to your computer and use it in GitHub Desktop.
Save basyusuf/53739ed91361234b641ae81a3d010d5f to your computer and use it in GitHub Desktop.
Helper Func S3
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