Skip to content

feat: add download_name parameter for custom download filenames#2813

Open
Br1an67 wants to merge 4 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 4 commits intoChainlit:mainfrom
Br1an67:fix/issue-2124-pdf-download-name

Conversation

@Br1an67
Copy link
Contributor

@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 while keeping inline viewing. The server sets an inline Content-Disposition and filename using download_name, falling back to name.

  • New Features
    • Element.download_name optional field; serialized as downloadName, restored via to_dict/from_dict, persisted via persist_file, and added to FileDict.
    • File responses set inline Content-Disposition with filename from download_name (fallback to name).

Written for commit c15c275. 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
hayescode
hayescode previously approved these changes Mar 5, 2026
hayescode and others added 2 commits March 5, 2026 16:34
Add the missing download_name field to FileDict to fix mypy error
in session.py where download_name was used but not defined in the
TypedDict.

Co-Authored-By: Claude <noreply@anthropic.com>
@Br1an67 Br1an67 force-pushed the fix/issue-2124-pdf-download-name branch from b061416 to c15c275 Compare March 6, 2026 04:39
@Br1an67
Copy link
Contributor Author

Br1an67 commented Mar 9, 2026

Hi — just a gentle bump on this. Happy to make any changes if needed!

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

2 participants