Opening File Saved to /tmp/debug.txt

Ah, the thing you’re encountering is that Data Files is read-only by default! If you want to upload changes, you’ll want to do it explicitly (because of the reasons @stefano.menci talks about): write to the filesystem, then use anvil.media.from_file() to turn it into a blob you can store in a database row.

An approach that might work, given that I believe you’re talking about a background task, would be to:

  • For each background task execution, create a new temporary file (with a random name so that concurrent executions don’t collide)
  • Write the data incrementally to that file
  • At the end of the background task, read the file into a Media object with anvil.media.from_file() and add it as a new row to a logs table (perhaps with some other columns indicating information about the run, so you can find the right log later)

That way, you can log large amounts of information and organise it sensibly.

1 Like