Create pdf and upload it to AWS S3 (React, NodeJS)
Published in
2 min readMar 6, 2019
I would need to create a pdf file from taking screen shot of the react application (div element), then upload the pdf to AWS S3 through NodeJS.
It is straight forward for uploading the file/image to AWS S3 from nodeJS, but there are some challenges on creating pdf and convert it to the right format in order for the uploading.
React
- use html2canvas to capture the screen shot of an div element.
- convert it to dataURL
- create a pdf by jsPDF
- convert it back to dataURL (pdf version)
NodeJS
- convert dataURL to buffer by data-uri-to-buffer package (https://www.npmjs.com/package/data-uri-to-buffer)
The rest is just the regular upload file to AWS S3 from NodeJS. (need buffer in the body)
Here are a few reference
https://stackoverflow.com/questions/13807339/upload-a-binary-file-to-s3-using-aws-sdk-for-node-js