Skip to content

Instantly share code, notes, and snippets.

@mpvvliet
Last active November 2, 2018 21:21
Show Gist options
  • Save mpvvliet/ad943a3ae5dbd65f555ceeb227e0b02e to your computer and use it in GitHub Desktop.
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.
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