Export table with Media column?

Files are stored in the table with Media column. When downloading the cvs file in the table service, this is what I have
image

It seems that the files is not stored in the cvs. Is there a way to do that without code being written?

Unfortunately this is not possible as far as I’m aware. Also, how would you represent the audio file in a CSV?

I am not too sure if get_bytes() does the trick?

I was just curious. Yes, you could get the bytes and write those to a table I suppose. That might be feasible, depending on the audio files and what you want to do with that raw data. You would have to write that code though of course.

I’d probably use Pandas to make a nice little table that has exactly what I want in it, and then download that (or store the audio files somewhere else and link to them in the table; no idea if that would work for your purposes).

Thanks @alcampopiano I have to find a way to convert that raw data back to the audio/image/word/excel file then, not sure if feasible.

Other option is to upload the file into the _/theme, but I don’t know how to do it yet. Google drive is another option though I really want to achieve the goal using Anvil only.

Maybe you can give a little more detail on why you need a table of media objects to be downloaded?

The uploading to _/theme Idea might not be good practice since my understanding is that it’s not intended for that purpose but more a place to store HTML/css/js as well as some permanent media like an image… rather than dynamically uploaded media.

From recent posts I understand you want to be able to play media on the client and using the datatable url seemed sufficient for that? What are we missing?

Hi @stucork, it is a separate issue since I just want to keep a backup of my database so I can moving to the the anvil-app-server in VPS

If the files in the Media column are not included in the cvs file, then the backup doesn’t work.

I am working on the google drive, but struggle to get the url of the file saved on it

to get the url of a drive file:

file = app_files.file
url = file.get_url()
# will get the location of the file in anvil to be downloaded

info = file._obj
link = info['alternateLink']

_obj is not documented and can’t be relied upon (as far as I’m aware)

but if you do

print(file._obj.keys())

you’ll get some more currently available options…

1 Like

Many thanks for that. I guess the migration process will be temporarily upload all files to google drive and then download the file back to the table

By the way, is there any way to change file name saved in the table?

I would play with the functions from anvil.media which has a name property…

https://anvil.works/docs/media#files-in-server-modules

import anvil.media

media_object = anvil.BlobMedia('text/plain', b'Hello, world', name='new.txt')

with anvil.media.TempFile(media_object) as file_name:
    # Now there is a file in the filesystem containing the contents of media_object.
    # The file_name variable is a string of its full path.

and

import anvil.media

anvil.media.from_file(file_name, [content_type], [name])import anvil.media

anvil.media.from_file(file_name, [content_type], [name])

Thanks @stucork, really appreciate that