Why PDFDocument.load() is not working with lambda ? #1100
Unanswered
parthshah27
asked this question in
Q&A
Replies: 1 comment
-
const s3 = new AWS.S3();
const { Body } = await s3
.getObject({
Bucket: 'bucket',
Key: templateObjectKey,
})
.promise();
const pdfDoc = await PDFDocument.load(Body as Buffer); works for me |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a lambda function in which I'm passing the public URL of the pdf file which is located in s3. I'm converting that file to buffer and passing that buffer data to load() function but It throwing an error. "The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Uint8Array". Please check the below code to get a better understanding.
const existingPdfBytes = await axios.get("https://yamaha-finance.s3.ca-central-1.amazonaws.com/zip/dummy.pdf", { responseType: 'arraybuffer', headers: { 'Accept': 'application/pdf' } }); console.log("[BUFFER DATA]",existingPdfBytes.data); var bytes = new Uint8Array(existingPdfBytes.data); const pdfDoc = await PDFDocument.load(existingPdfBytes.data);
code: 'NetworkingError',
region: 'ca-central-1',
hostname: 'yamaha-finance.s3-ca-central-1.amazonaws.com',
retryable: true,
time: 2021-11-23T14:17:16.931Z
}
`
Does anyone have an idea how to resolve it? Same code is working fine in local
Beta Was this translation helpful? Give feedback.
All reactions