Hi all,
I’m working with st.file_uploader and noticed that when I switch between different key values, the uploaded file disappears.
Minimal example:
import streamlit as st
toggle = st.checkbox("Use alternate uploader key")
key = "uploader_alt" if toggle else "uploader"
uploaded_file = st.file_uploader("Upload a file", key=key)
if uploaded_file:
st.write(f"Uploaded file: {uploaded_file.name}")
If I upload a file, then toggle the checkbox (changing the key), the uploader resets and I lose the file. Switching back to the original key doesn’t restore it either.
Is this the expected behavior? If so, is there a workaround to persist the uploaded file when changing keys?
Thanks!