I read a few other posts on this, but I didn’t exactly understand and they were closed. I’m trying to figure out where the files that are uploaded using st.file_uploader are stored.
I didn’t see anywhere in my streamlit account to access files that have been uploaded or similar. If the files aren’t accessible anywhere, does anyone have a suggestion for a small (~15gb/yr) amount of storage that will play nicely with streamlit’s upload and then data processing?
st.file_uploader does not save files to disk. The returned file(s) exist in memory in your Python environment. Just like x=2 stores an integer value assigned to x, y=st.file_uploader("Files") stores an UploadedFile (extension of BytesIO) assigned to y. (…or list of UploadedFile when multiple files are allowed)
If you need to work with your files on disk, you’ll have to manually write them to a file or use tempfile to create a temporary file on disk.
One other thing to note is that your files exist on disk until the application is restarted. If you want to persist them, you should use a cloud storage solution such as GCS or AWS S3.
What if I do not want to persist the files but I don’t want to store the files in memory?
In my use case it would be useful to have users essentially have their own instance of the app and its backing filesystem. I was kind of hoping that we could specify that when a new user connects to the app, a new system and environment would be spun up.
I understand that we could use tempfile to create a unique directory or use files in memory. The former would be non-ideal because I’d like users to be able to reload their created files if they reconnect to a new session (like if they used the app on their own laptop). The latter would be non-ideal because sometimes memory usage in the app can be very high and very many files could be generated.
Is there any way to force a new app instance for each session or user? Or is a shared deployment just the way Streamlit Community Cloud works?
When you deploy an app to Community Cloud, you have one Streamlit server running your app. When a user visits you app, a thread is created to handle their session. You have one file system in one environment running that one Streamlit server. Files on disk are accessible to that Streamlit server and thus to all sessions. Session State is something that is unique to each session, but it is something that is “in memory” and not on disk.
If you don’t want files to persist, but do want them on disk, there isn’t anything to logically isolate those files for a Community Cloud app (at leas for files written to the Community Cloud environment). Tempfile is the best thing I know about to write things temporarily to disk.
If you want to save files that users can reload, I recommend using an external storage solution for that, like @Alexandru_Toader mentioned.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.