I am trying to download a PDF file from S3 using AWS SDK for JavaScript V3('aws-sdk/client-s3') in Node JS. It works fine for plain text files but not sure how PDF stream to PDF file. Appreciate any help
I wrote a sample Node JS modules and s3Module.js returns the ReadableStream from the getObject call from AWS. I tried different ways to download the file but the PDF is generated with zero bytes. The Body of the response is visible in the VSCode.
I think I am missing encoding or something. Appreciate any help.
s3Module.js
const response = await s3.send(new GetObjectCommand({Bucket:'bucket',Key:'key'});
console.log(response) //print whole ReadableStream
const body = response.Body;
body.pipe(fs.createWriteStream("Test.PDF")) //There was an error opening this document. The file is damaged and could not be repaired.