Skip to content

feat: add download_name parameter for custom download filenames#2813

Open
Br1an67 wants to merge 2 commits intoChainlit:mainfrom
Br1an67:fix/issue-2124-pdf-download-name
Open

feat: add download_name parameter for custom download filenames#2813
Br1an67 wants to merge 2 commits intoChainlit:mainfrom
Br1an67:fix/issue-2124-pdf-download-name

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

What

Add a download_name optional parameter to Element so developers can specify a human-readable filename for file downloads.

Closes #2124

Why

When using cl.Pdf with 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: Add download_name: Optional[str] = None to Element base class, pass it through persist_file()
  • backend/chainlit/session.py: Accept and store download_name in the file dict
  • backend/chainlit/server.py: Use download_name (falling back to name) in FileResponse with content_disposition_type="inline" to set the download filename while preserving inline display

Usage

pdf = cl.Pdf(
    name="My Report",
    path="./report.pdf",
    display="inline",
    download_name="UserFriendlyReport.pdf"
)

Without download_name, the element's name is used as the download filename (still better than the UUID).

Testing

Backward compatible — download_name defaults to None, falling back to existing name field.


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.

  • New Features
    • Element.download_name optional field; included in ElementDict and preserved through to_dict/from_dict and persist_file.
    • File responses set the download filename from download_name (fallback to name) with inline Content-Disposition.

Written for commit 9522b81. Summary will update on new commits.

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.
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. backend Pertains to the Python backend. enhancement New feature or request labels Mar 1, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom file name for cl.Pdf

1 participant