Created
January 21, 2018 03:45
-
-
Save pavelvlasov/6f89840dcbb9daf4b94730c56c11de09 to your computer and use it in GitHub Desktop.
html to png handler
This file contains 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
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