How to get node.js to wait until pdfkitDocument.on(‘end’) finishes completely
We have an application that uploads a PDF to S3 and returns an object with metadata about the S3 file. This works fine if we want to email the link to the document to someone. The problem comes if we want to download the file from S3 immediately thereafter, for instance, to attach the file to a message vs. a link to the file. What seems to be happening is that the metadata regarding the S3 file is returned to the calling function BEFORE the pdf.on(‘end’) code is executed which triggers the upload to S3. The relevent code snippet is here: