What is the best way to upload download files during app run?

What I’m trying to do:
Trying to figure out if there is a kind of directory that I can communicate with during the app run.
So for example my app read some file and then create a new one that I would like to save and read it later.
What is the best method to do it?
There is asset, files, Google Drive, but all of them seems to be static.

Anvil isn’t designed to work with the file system, because the server environment spins up new for each server function call, so you don’t have a persistent file system to work with. Instead, Anvil uses Media objects, which you can create, return to the client, store in data tables, etc. You’ll want to read up on Media objects in the docs and the forum.

Ok, but how can I do it during run?
I don’t need persistent file system, but rather way to communicate with the files that I just created.
Can you give a link to some tutorial or some piece of code?

These two statements are in conflict:

image

This assumes the answer to @stefano.menci 's concern is that by “read it later” they mean further down the code within one server call, but that could be incorrect.

Later means after few min of the app run.

Please read through the docs on Media objects, and search the forum for examples. This is a question that’s been asked often, and there are examples out there.

You can store files in the /tmp/ directory iirc, for short term use, but I think it’s better to store in a variable and pass it around or use the built in database if you need it persistant.

Currently it seems to work fine thanks for the help.

You can only rely on that if you have the persistent server option. Otherwise the file system can be wiped out between calls.

1 Like

Store it in the database and it’s not needed delete it. That is that simple. It’s better than passing it dozens of times from func. to function

Good info thanks, is that true also true if you using your own server as a backend? Also do you know where the file is stored when you use this command, it’s not the tmp folder?

with anvil.media.TempFile(media_object) as file_name:

You don’t have to ask us! Try

with anvil.media.TempFile(media_object) as file_name:
    print(file_name)
2 Likes