feat: add download_name parameter for custom download filenames#2813
Open
Br1an67 wants to merge 2 commits intoChainlit:mainfrom
Open
feat: add download_name parameter for custom download filenames#2813Br1an67 wants to merge 2 commits intoChainlit:mainfrom
Br1an67 wants to merge 2 commits intoChainlit:mainfrom
Conversation
Add download_name optional field to Element base class so developers can specify a human-readable filename for downloads instead of the UUID-based name. The file serving endpoint now sets Content-Disposition with the download_name (falling back to name) while keeping inline display for PDFs and other embedded elements.
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/chainlit/element.py">
<violation number="1" location="backend/chainlit/element.py:100">
P2: `download_name` was added to `Element`, but serialization/deserialization (`ElementDict`, `to_dict`, `from_dict`) was not updated, so custom download filenames will be dropped when elements are persisted or rehydrated.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Add downloadName to ElementDict TypedDict - Include download_name in to_dict() output - Restore download_name in from_dict() via common_params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add a
download_nameoptional parameter toElementso developers can specify a human-readable filename for file downloads.Closes #2124
Why
When using
cl.Pdfwith a file path, Chainlit persists the file with a UUID-based name. When users download the PDF from the browser's viewer, they get a UUID filename instead of the original name.Changes
backend/chainlit/element.py: Adddownload_name: Optional[str] = NonetoElementbase class, pass it throughpersist_file()backend/chainlit/session.py: Accept and storedownload_namein the file dictbackend/chainlit/server.py: Usedownload_name(falling back toname) inFileResponsewithcontent_disposition_type="inline"to set the download filename while preserving inline displayUsage
Without
download_name, the element'snameis used as the download filename (still better than the UUID).Testing
Backward compatible —
download_namedefaults toNone, falling back to existingnamefield.Summary by cubic
Add a download_name option to Element so files (e.g., PDFs) download with a human-friendly filename. The value is serialized with the element and used by the server while keeping inline viewing.
Written for commit 9522b81. Summary will update on new commits.