Get CSV from DB to client to file

You’d think this would be a no-brainer.

I used to_csv on the DB rows & got it into a variable (who knows what type it is??!!!).
Then I’ve tried to convert it to everything from blobs to bytes to . . whatever so when I pass it to the client I can downlaod the csv.
I’m getting lazymedia acusations and 100 others.

Just be great sometiems if you guys would have a FULL example of somethign as simple as this.

What do I do? Please.

SERVER

  tblAsCSV = app_tables.test_sentences_tbl.search().to_csv()
  csv_media = anvil.BlobMedia('text/plain', tblAsCSV.encode(), name=tblName + '.csv')
  return csv_media

CLIENT

    csv_media = anvil.server.call('exportDB', tblType)
    csvFile = anvil.BlobMedia('text/plain', csv_media, name=tblType + '.csv')
    # bytes(tblAsCSV, 'utf-8')
    anvil.media.download(csvFile)

And
convert lazymedia to byte string
doesn’t exist on the internet

I’ve of coursed tried lots of simpler things already.

SERVER

@anvil.server.call
def export_db():
  csv_media = app_tables.test_sentences_tbl.search().to_csv()
  return csv_media

CLIENT

    csv_media = anvil.server.call('export_db')
    anvil.media.download(csv_media)
5 Likes

I tried that !!!
(Obviosuly with a typo or something)

Thank you @stucork for providing assistance to Paul.