How convert pdf to media object

What I’m trying to do:

I have uplink script running as server on my machine. This script generates pdf files. I want to return the pdf file as anvil media object so anyone from client side download it using anvil.media.download.

What I’ve tried and what’s not working:
I have tried to convert pdf into media object with following code

media_obj = anvil.media.from_file("test.pdf","application/pdf")

But the above code returns a NoneType not a media object.

Can anyone tell how can I make this thing works. On the sidenote, can anvil.pdf convert html string to pdf. I didn’t find that in docs.

In my experience, when any file operation fails unexpectedly, the first thing to check is “Did I provide the full path to the file?” In this case, the answer is “no”, so now there are two things to check:

  1. What is the current drive and directory at the time the above function is called?
  2. Where did the file end up? Is it in the then-current directory? Or somewhere else?

With those answers, it should be easy to make sure that the function is receiving the correct filename and path. There may be other issues, but at least you’ve eliminated one (very common) possibility.

1 Like

@p.colbert Thanks, it was just a silly error on my part. I fixed the issue.

1 Like