0

I currently have a PDF file that I'm getting from an Amazon s3 bucket logging out data like below in the console.

Uint8Array(83284) [37, 80, 68, 70, 45, 49, 46, 53, 10, 37, 191, 247, 162, 254, 10, 49, 48, 32, 48, 32, 111, 98, 106, 10, 60, 60, 32, 47, 76, 105, 110, 101, 97, 114, 105, 122, 101, 100, 32, 49, 32, 47, 76, 32, 56, 51, 50, 56, 52, 32, 47, 72, 32, 91, 32, 55, 55, 53, 32, 49, 53, 51, 32, 93, 32, 47, 79, 32, 49, 52, 32, 47, 69, 32, 53, 50, 54, 50, 53, 32, 47, 78, 32, 51, 32, 47, 84, 32, 56, 50, 57, 53, 55, 32, 62, 62, 10, 101, 110, 100, …]

I'm trying to display this PDF file with this Uint8Array data using react-pdf but react-pdf shows "No PDF file" error.

What do I need to do to get this to work in react-pdf?

Adebola
  • 549
  • 1
  • 7
  • 11

1 Answers1

0

It depends on the way this Uint8Array is stored in the bucket.

One you thing you can try is to convert it into a blob, with .pdf extension

const blob = new Blob(s3Bucket, { type: 'application/pdf' });

If this doesn't work, I am afraid you might have to modify the uploading logic to set the type and disposition to

Content-Type: "application/pdf"
Content-Disposition: inline;
Ahmed Hammad
  • 2,798
  • 4
  • 18
  • 35