How to save Google Drive file as DB media object

I’m trying to save a Google Drive file as DB media object:

f_gdrive = app_files.data_csv
app_tables.filetbl.add_row(file=f_gdrive, name='data_csv')

This throws an error:

anvil.server.InternalError: Internal server error: e18a54ec72e5
at /downlink/anvil/_threaded_server.py, line 309
  called from /downlink/anvil/_server.py, line 40

I have successfully got data out of the f_gdrive but I don’t want to read it in every run.
So, how can I save it in my file table where the ‘file’ field is of Media Object type?

Hi there,

If I understand correctly, you will probably want to convert your google drive file to Blob Media first.

Something like the following:

my_file = app_files.my_google_drive_file_csv
  
media=anvil.BlobMedia('text/csv', my_file.get_bytes(), name='my_file.csv')
  
app_tables.my_table.add_row(media_column=media)
3 Likes

Thanks campopianoa!
That was the missing piece of knowledge . .

1 Like