I’m trying to convert an image from the fileloader to a pdf.
Pseudo code:
1. when file added using fileloader upload to googledrive folder
2. get url of file
3. from url open this as an image in PIL.Image (use of response library and io.BytesIO)
4. save PIL.Image as pdf
5. upload pdf to google drive
I’m not sure how to get from steps 4 to 5. I don’t know where the saved PIL.Image PDF is in order to then upload it to google drive.
normally this would be a file within the current directory so I’m not sure how to access it.
You can write to /tmp just as you would write to your own hard drive. You have your own private space on the Anvil servers. The file might not survive server calls (I’m not 100% sure when the /tmp is purged).
You can read the contents of the file into a binary string, then create a BlobMedia with it. Then you can pass that media object into add_row() on a database table which has a Media column.
BTW, you won’t want to call get_url() on a Media object from a table (that will get you a temporary URL that’s only valid from this browser session, which is no good if you want to pass it to an API). Instead, create an HTTP Endpoint in your Anvil app, and have that return the appropriate Media when you call it. (You can use parameters to request different files from the same endpoint.)