Skip to content

Conversation

@rishabhjain1712
Copy link
Contributor

@rishabhjain1712 rishabhjain1712 commented Oct 19, 2025

Title

Add max_upload_size parameter to st.file_uploader to limit file size per widget


Description

This PR implements the requested enhancement from issue [#12692](#12692):

  • Added an optional max_upload_size parameter to st.file_uploader().
  • Allows developers to restrict the maximum file size for each uploader individually.
  • If max_upload_size is not provided, the widget falls back to the global server.maxUploadSize configuration.
  • Files exceeding the max_upload_size limit are blocked before upload, improving UX and saving bandwidth.

Closes #12692
Closes #12579

@snyk-io
Copy link
Contributor

snyk-io bot commented Oct 19, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@jrieke jrieke added the status:needs-product-approval PR requires product approval before merging label Oct 20, 2025
@sfc-gh-bnisco sfc-gh-bnisco added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Oct 20, 2025
@jrqysxkmrh-afk
Copy link

Just looked for this option and found this PR :)
Waiting to see when it will be merged

@jrieke
Copy link
Collaborator

jrieke commented Oct 31, 2025

@rishabhjain1712 seems like this doesn't work when I try it out, see my comment above.

@rishabhjain1712
Copy link
Contributor Author

rishabhjain1712 commented Nov 7, 2025

@jrieke pushed the changes, request you to take a look

@jrieke
Copy link
Collaborator

jrieke commented Nov 10, 2025

Looks good from product side! I thought about the parameter name today, and I think we should actually switch to max_upload_size since a) it's easier to understand what exactly this parameter is doing (in contrast to e.g. the size of the widget – e.g. we use size for st.logo) and b) to be more aligned with the config option server.maxUploadSize.

I think we'll definitely also want some tests for this, but will pass it to our engs for proper review.

@jrieke jrieke added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Nov 10, 2025
@rishabhjain1712
Copy link
Contributor Author

@jrieke changed the name to max_upload_size, this is ready to merge.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a max_upload_size parameter to st.file_uploader() to enable per-widget file size limits, addressing issue #12692. When not specified, the widget falls back to the global server.maxUploadSize configuration.

Key Changes

  • Added max_upload_size parameter to both the public and internal file_uploader methods
  • Implemented conditional logic to use the parameter value or fall back to the global config
  • Parameter is passed through to the protobuf's max_upload_size_mb field

@rishabhjain1712
Copy link
Contributor Author

@jrieke should i resolve the conflicts by accepting both changes current and incoming changes?

@jrieke
Copy link
Collaborator

jrieke commented Nov 19, 2025

@rishabhjain1712 Pinged our eng team to give you some help :) I think we definitely also need some tests for this.

Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I have some feedback inline, and some +1s to some feedback left by Copilot.

self,
label: str,
type: str | Sequence[str] | None = None,
max_upload_size: int | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: @jrieke should we consider also adding this param to st.audio_input, since that returns a file that is bounded by server.maxUploadSize

@sfc-gh-bnisco sfc-gh-bnisco self-assigned this Nov 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@sfc-gh-bnisco sfc-gh-bnisco changed the title Add max_size parameter to file_uploader to limit file size per widget Add max_upload_size parameter to file_uploader and chat_input Dec 6, 2025
@sfc-gh-bnisco sfc-gh-bnisco added feature:st.file_uploader Related to the `st.file_uploader` widget feature:st.chat_input Related to the `st.chat_input` widget labels Dec 6, 2025
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sfc-gh-bnisco sfc-gh-bnisco added the security-assessment-completed Security assessment has been completed for PR label Dec 8, 2025
@sfc-gh-bnisco sfc-gh-bnisco merged commit 6f036b6 into streamlit:develop Dec 8, 2025
54 of 57 checks passed
@jrieke
Copy link
Collaborator

jrieke commented Dec 10, 2025

Wohoo, thanks for getting this in @rishabhjain1712! Would love to send you some swag as a little thank you, just fill out this form and we'll get it on the way: https://forms.gle/RZCUTKCrg7aHyqH78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation feature:st.chat_input Related to the `st.chat_input` widget feature:st.file_uploader Related to the `st.file_uploader` widget impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR status:product-approved Community PR is approved by product team

Projects

None yet

5 participants