Skip to content

Instantly share code, notes, and snippets.

@pavelvlasov
Created January 21, 2018 03:45
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 pavelvlasov/6f89840dcbb9daf4b94730c56c11de09 to your computer and use it in GitHub Desktop.
Save pavelvlasov/6f89840dcbb9daf4b94730c56c11de09 to your computer and use it in GitHub Desktop.
html to png handler
export const handler = async (
event: Event,
context: Context,
callback: Callback
) => {
try {
const body = validateBody(event.body);
const image = await takeScreenshot(body.html, body.width, body.height);
const res = await new Promise((resolve, reject) => {
const s3 = new S3({
apiVersion: "2006-03-01",
region: "us-east-1"
});
const params = {
Bucket: bucketName,
Key: body.name,
Body: image,
ContentEncoding: "base64",
ContentType: "image/png"
};
s3.upload(
params,
(err: Error, uploadResult: { Location: string }) => {
if (err) {
return reject(err);
}
resolve({ imageUri: uploadResult.Location });
}
);
});
callback(null, res);
} catch (err) {
callback(err);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment