Hi,
I’m creating an application that has a chat_input function, and I would like to know if there’s a way to access uploaded imaged before being submitted to the chat.
Basically right now chat_input does not disable the submit button if the image uploaded is too big, allowing the user to submit the text without image. I would like to have access to the files after uploading and before submission in order to crontrol the state of the submit button
I’m using streamlit version 1.55
Thanks!
Welcome to the community and thanks for your thoughtful question!
My understanding is that with Streamlit’s st.chat_input, you can only access uploaded files after the user submits the chat input—there’s no built-in way to access or validate files before submission or to control the submit button’s enabled/disabled state based on file size or other criteria. The widget’s return value (including files) is only available after submission, and there’s no documented callback or pre-submit hook for file validation in st.chat_input as of version 1.55.0. See the official docs for details: st.chat_input API.
If you need to validate files before submission, you might consider using st.file_uploader outside the chat input to handle file uploads and validation, then enable the chat input or its submit button based on your checks. However, this would change the user experience compared to having everything in the chat input. There’s currently no documented way to disable the st.chat_input submit button dynamically based on file state, and no pre-submit access to files is mentioned in the docs or recent release notes.
Sources: