I need that only the single file to be displayed here, because others are duplicates.
It would be great if you also tell me how to clean file_uploader session of duplicates.
I need that only the single file to be displayed here, because others are duplicates.
Hi @intolighter,
The only way to remove an uploaded file without exiting or refreshing the app is for the user to click the “x” button – in other words, this isn’t possible programmatically.
Caroline
Hi @intolighter,
This could be solved by resetting uploader’s key every time after upload
import streamlit as st
if 'ctr' not in st.session_state:
st.session_state['ctr'] = 0
if 'docs' not in st.session_state:
st.session_state['docs'] = []
def uploader_callback():
if st.session_state[st.session_state['ctr']] is not None:
new_files = st.session_state[st.session_state['ctr']]
for i in new_files:
st.session_state['docs'].append(i.name)
st.session_state['ctr'] += 1
st.file_uploader(
label="File uploader", on_change=uploader_callback, key=st.session_state['ctr'], accept_multiple_files= True
)
st.write(st.session_state)
And streamlit automatically forgets old keys so no need to worry about that also
Hi @intolighter
Programmatically, there’s no way to remove an uploaded file without requiring the user to click the “x” button. This means that you must manually interact with the interface to delete the file, and it cannot be done automatically through code. So it’s an easy step to follow.
Hope it will help you
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.