Thanks to visit codestin.com
Credit goes to github.com

Skip to content

file_uploader allows to remove files despite disabled = TrueΒ #12146

@Andrea-Oliveri

Description

@Andrea-Oliveri

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Good Afternoon,
Thank you for this powerful library πŸ˜„ .
I have noticed a small bug with st.file_uploader : regardless of whether disabled is True or False, it is always possible to remove files in the GUI.
As a result, this will trigger an app rerun.
Below a piece of code to reproduce the issue.

Reproducible Code Example

Open in Streamlit Cloud

import streamlit as st

st.session_state["disable"] = st.session_state.get("disable", False)
st.session_state["counter"] = st.session_state.get("counter", 0) + 1

st.info(f"Script rerun {st.session_state["counter"]} times")

files = st.file_uploader(label = "", disabled = st.session_state["disable"])

st.info(f"File uploaded: {files is not None}")

button = st.button("Enable" if st.session_state["disable"] else "Disable")
if button:
    st.session_state["disable"] = not st.session_state["disable"]
    st.rerun()

Steps To Reproduce

  1. Run the app
  2. Upload any file
  3. Click on the "Disable" button

At this point, notice how you can't click the file_uplaoder to change the file.
Also note what the number of reruns is.
Finally, notice how the script can indeed see a file was uploaded (as shown in st.info)

  1. Click on the X at the right of the uploaded filename

At this point, notice how you still can't click the file_uplaoder to change the file (which if good).
Also note that the number of reruns has increased (this is not good).
Finally, notice how the script can detect file_uploader no longer storing a file.

Expected Behavior

I would expect disabled parameter of st.file_uploader to both:

  1. Not allow to replace the uploaded file(s) --> current behaviour
  2. Not allow to remove any previously uploaded file(s) --> improvement

Current Behavior

Explained in the steps to reproduce

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.47.0
  • Python version: 3.13.2
  • Operating System: Windows 11 Enterprise 23H2
  • Browser: Edge

Additional Information

No response

Metadata

Metadata

Assignees

Labels

feature:st.file_uploaderRelated to the `st.file_uploader` widgetpriority:P2Medium-high priority - fix within one monthstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions