What I’m trying to do:
I have Excel files stored in a data table. From the client I pass a server function the row ID in that table. On the Server Side I am trying to re-use code that processes a file (previously) passed from a file loader. When the FileLoader passes the file, the server identifies the type as <class ‘anvil.FileMedia’>. When the server code retrieves the file from a data table, it is identifying it as <class ‘anvil._server.LazyMedia’>
What I’ve tried and what’s not working:
I’ve looked at how to ‘convert’ that, but no dice. Ultimately what I need to do is read that file into a dataframe.
Thanks Phil, so I’ve tried several uses of get_bytes() to no avail. This is what I know:
From my client code when I call my server function with a file from a file loader, the server function shows me that the file type is anvil.FileMedia. With this, my server code receiving the file as a parameter works fine:
with anvil.media.TempFile(file) as file_name:
if file.content_type == 'text/csv':
however, different client code (trying to use the same server code) sending a file retrieved from a table is sending ‘file’ as LazyMedia to that server function. That… is not working. I wonder how on the client side I can retrieve that media object from my data table, but provide it as a parameter to the server function such that it’s also received as an anvil.FileMedia object?
Each of these is a subclass of anvil.media. So if I read the docs correctly, you should be able to call get_bytes() on that object, directly. No need to convert it into something else, first.
Not sure if it is relevant but perhpas a bug crept back in related to lazy media. But yeah, get_bytes() should be the answer (assuming there are bytes there).