PDF file preview not working with base64 string

Hi everyone!

I'm trying to use the pdf preview component but it doesn't seem to work.
The S3 resource query to read a file offers a data.Body but that body seems to be an octet-stream:

The component wants a base64 string representation of the file. I used btoa() in the S3 query results transformer to convert the Body string but it doesn't seem to like that:

Quick update:
I also tried turning the result into the object it seems to expect and now it returns a different error:

What am I missing?

Many thanks,
Fina

Ahaha just found the fix myself! :sweat_smile:
Leaving it here in case anybody else comes across the same issue:

The component needs an object in a specific shape but the body doesn't need to be converted! Here's the code snippet that made things work:

return {'base64Data': data.Body, 'name': 'file_name', 'type': 'application/pdf', 'sizeBytes': data.ContentLength}

3 Likes