Reading StreamingMedia type from uplink server

Hello,

I recently added an uplink to my project. I simply have a form that allows upload of a .txt file, and then I want to read and analyze that .txt file using a function on the local computer end of my uplink system. However, when I add a @anvil.server.callable and give the function a txt file, it throws this error. I have been trying to read it to a csv using pandas read_csv but no luck. Here’s the error:

TypeError: expected str, bytes or os.PathLike object, not StreamingMedia

Any help would be appreciated, thanks!

Hi, @tigeysky, and welcome to the Forum!

The topic you’re looking for in the Docs (see link at top of page) is “Files, Media and Binary Data”.

Pandas was created independently from Anvil (in fact, it’s much older). It won’t recognize Anvil objects, or know how to convert them into the raw data that read_csv needs. So that’s your responsibility. Have a look at the docs for Anvil Media Object’s get_bytes function.

2 Likes

Thanks and sorry for the novice question. For anyone interested I was able to work around this by passing the media object’s url and calling it in pandas read_csv function

No worries! With today’s changing technology, we’re all perpetual novices. :slightly_smiling_face: Just in ever-changing areas.

The docs (and search!) will help you find what you want, when you want or need it, at your own pace. Search also searches the Forum, so it’s more helpful than you may expect.

1 Like