Problem with presenting/downloading a PDF that is base64 encoded

(moved from a closed topic to a new one)

Hi meredydd, I’m struggling with presenting/downloading a PDF that is base64 encoded. Here is what I have tried:

byte_string = doc_base64.encode()
my_media = anvil.BlobMedia(content_type="application/pdf", content=byte_string, name="hello.pdf")
self.link_notification.url = my_media

I know doc_base64 is valid because I’ve copied and pasted the raw value into an online converter and the PDF is correct. However, when I try the above, I always get an invalid PDF format when I try to open the downloaded file. Should I be handling this in a different manner?

Thanks in advance,
David

Hi, @david1 Welcome to anvil. :slightly_smiling_face:

This topic was previously closed, so you should have started a new question, but this might help you anyway.

import base64
byte_string = doc_base64.encode("ascii")
byte_string = base64.b64decode(byte_string)
my_media = anvil.BlobMedia(content_type="application/pdf", content=byte_string, name="hello.pdf")
self.link_notification.url = my_media