Last active
November 2, 2018 21:21
-
-
Save mpvvliet/ad943a3ae5dbd65f555ceeb227e0b02e to your computer and use it in GitHub Desktop.
Code snippet showing how to store a rendered image from ChartJS node library in an S3 bucket.
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 aws = require('aws-sdk'); | |
const s3 = new aws.S3(); | |
async function storeImage(buffer) { | |
const imageFileName = "image.png"; | |
const object = { | |
Bucket: BUCKET_NAME, | |
Key: imageFileName, | |
ACL: "public-read", | |
Body: buffer | |
}; | |
try { | |
await s3.putObject(object).promise(); | |
return imageFileName; | |
} catch(err) { | |
console.error("Failed to store image: " + err); | |
throw err; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment