St.file_uploader() removing file after any triggered event

While using the st.file_uploader() feature in the latest release of streamlit==0.69.0, I noticed that after you successfully upload a file, the file is immediately removed after any action such as pressing a button or selecting an option from the st.mulitselect() and I am faced with the following error message:

‘cannot read an empty file’

It seems as though everything is being reset including the uploaded file. This was not the case in streamlit==0.60.0.

It’s likely that you need to reset your buffer with uploaded_file.seek(0) .

Previously we were creating a new buffer for you each time we reran. To optimize, we are returning the same buffer on rerun. Unfortunately, this means that if you’ve already read the buffer, you’ll need to reset after. If you use .getValue(), there’s no need to seek. If you are working with certain libraries, they are likely performing a read().

multiple_files = st.file_uploader('label', accept_multiple_files=True)
for file in multiple_files:
	file_body = file.read()
	file.seek(0)
2 Likes

Thanks! It works just fine now.

Sorry, but on a similar note I have a problem where my dataframes are being lost after I press a button. Is there anyway to preserve a dataframe?

Could you clarify what you mean by dataframes are being lost? Is the dataframe populated with data from a file uploader and the contents of the file uploader is disappearing? Sample code would be super helpful