Using Session state with file uploader

Hi,
I’ve been very happy using the file uploader except for the fact that we can’t reset it…
Here is my setup :
The user fills a textinput, some data is processed and then the user uploads a zip file.
I need to monitor the textinput and the zipfile to make sure there are no unanticipated changes, knowing that there are a bunch of other widgets before and after those two (and in between)…
It works well for the text input, but not for the zip file, because my guess is the file being stored in memory, some of its metadata must change each time there is a refresh due to a widget interaction (or is there some more subtle reason maybe ?).

Here is a sample code :

id = sidebar.text_input('ID', default_value)
if id != default_value:
	#do_stuff
	zip_bunch = file_uploader('Upload all the things', type='zip')
    if zip_bunch is not None:
    	session_state = SessionState.get(current_ID = id, zip = zip_bunch)
        if session_state.current_ID != id:
            error('Please reload the page before changing the ID.')
        elif session_state.zip != zip_bunch:
            error('Please reload the page before uploading a new zip file.')
        else:
            with ZipFile(zip_bunch, 'r') as zip_ref:
                zip_ref.extractall(folder_path)

SessionState is as defined in this thread :

How can I make this work ?
Thanks for any help !

3 Likes