← Back to list

Resetting the Streamlit File Uploader

How can you remove the files from st.file_uploader without have to do this manually?

UnicornOnAzur in Top Python Libraries · 2026-07-19 12:38 · 0 claps · 2.5 min read
#streamlit #streamlit-app-deployment #python-programming #python-app-development #python-control-flow
Open on Medium ↗
Wiki topics: 💻 · Programming

Resetting the Streamlit File Uploader

How can you remove the files from st.file_uploader without have to do this manually?

Sometimes, you might want your Streamlit app to automatically remove uploaded files from the st.file_uploader. This is especially useful when you’re running heavy computations on the input, as it can slow down your app or lead to unnecessary work. While there isn’t a standard method in the Streamlit documentation yet, there are two main options to consider. After reviewing numerous discussions and issues on the Streamlit forum, which I’ve linked at the end of this article, I’ve summarized these two key options and included an additional potential solution. You can check out this app, https://reset-file-uploader.streamlit.app/, which showcases all these options, and this article serves as a placeholder for any future solutions.

Image created with MagicStudio

Image created with MagicStudio

Ways to reset the file uploader

There are two ways to reset the st.file_uploader, by changing the unique key of the widget and by using the clear_on_submit when used within a st.form.

1. Resetting the key

As long as the widget identity remains the same and that widget is continuously rendered on the frontend, then it will be stateful and remember user input.²

The first approach is changing the key assigned to the widget. This changes the identity and makes it forget user input i.e. clearing the input. The key of the st.file_uploader is changed by having an incrementing number add to the key after every upload. key=f”uploader_key_{st.session_state.unique_key}” creates the new key and the value unique_key is incremented.

1a Using st.rerun

A variant is calling st.rerun() which reruns the app, changes the key and thus clears the input.

uploaded_file = st.file_uploader(
    "Upload a file", key=f"uploader_key_{st.session_state.unique_key}")
if uploaded_file is not None:
    st.session_state.unique_key += 1
    st.rerun()

1b Using user interaction

Another way to trigger a rerun is by having another widget interaction³, for example with a button click.

uploaded_file = st.file_uploader(
    "Upload a file", key=f"uploader_key_{st.session_state.unique_key}")
if uploaded_file is not None:
    st.session_state.unique_key += 1
right.button("Click")

1c. using on_change

Something I haven’t seen yet but that does work is using the on_change parameter. After your uploaded file has been handled, the unique_keyis incremented and on the following rerun the st.file_uploader is reset.

def callback():
    # Do something
    st.session_state.unique_key += 1

st.file_uploader(
    "Upload a file", key=f"uploader_{st.session_state.unique_key}",
    on_change=callback)

2. Using clear_on_submit

A completely different approach is using and resetting the widget within a st.form. With the clear_on_submit parameter of the form, all widgets, including the uploader, are cleared.

form = st.form("form", clear_on_submit=True)
form.file_uploader("Upload a file")
form.form_submit_button()

To conclude

In the end, resetting or clearing this widget isn’t that difficult. Hopefully this story contribute to some MWE of how to do so.

This story is my way to share my coding experience and the lessons I learned, and to document my solutions. All claps, comments, and highlights are appreciated, as well as sharing the story. For more code and my other links see: https://github.com/UnicornOnAzur/.

[1] https://docs.streamlit.io/develop/api-reference/widgets/st.file_uploader

[2] https://docs.streamlit.io/develop/concepts/architecture/widget-behavior

[3] https://docs.streamlit.io/develop/concepts/architecture/fragments

  1. June 2021, “Clear the cache for file uploder on streamlit
  2. August 2021, “Add form.clear() to the API
  3. November 2022, “File_uploader — How to clear the list of uploaded files?
  4. April 2023, “Are there any ways to clear file uploader values without using streamlit form
  5. May 2023, “Uploaded file not removed even upon app refresh
  6. Jule 2023, “Clear st.file_uploader without using st.form
  7. Jule 2023, “How to remove the uploaded file in Streamlit when clicking on the self-made “Reset all” streamlit button?
  8. January 2024, “Clear file after use file_uploader
  9. April 2024, “ Clear the file_uploader after using the file data
  10. August 2025, “Add a “clear all” button to file uploader

메타데이터
post_id
cd6ce133283a
slug
resetting-the-streamlit-file-uploader-cd6ce133283a
url
https://medium.com/top-python-libraries/resetting-the-streamlit-file-uploader-cd6ce133283a
canonical_url
https://medium.com/top-python-libraries/resetting-the-streamlit-file-uploader-cd6ce133283a
author_url
https://medium.com/@unicornonazur
status
ok
fetched_at
2026-08-03 23:05:12