Skip to content

feat: make file uploads directory configurable via config.toml#2815

Open
Br1an67 wants to merge 3 commits intoChainlit:mainfrom
Br1an67:fix/issue-2155-configurable-uploads-dir
Open

feat: make file uploads directory configurable via config.toml#2815
Br1an67 wants to merge 3 commits intoChainlit:mainfrom
Br1an67:fix/issue-2155-configurable-uploads-dir

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 1, 2026

What

Add a files_dir option to [features.spontaneous_file_upload] in config.toml to override the default .files directory.

Closes #2155

Why

The .files directory is hardcoded, which is problematic when Chainlit runs in environments where the user doesn't control the app directory.

Changes

  • backend/chainlit/config.py: Add files_dir: str = ".files" to SpontaneousFileUploadFeature, add it to TOML template, replace module-level FILES_DIRECTORY with get_files_directory() function that resolves relative paths from APP_ROOT
  • backend/chainlit/session.py: Use get_files_directory() instead of FILES_DIRECTORY
  • backend/chainlit/server.py: Use get_files_directory() for cleanup on shutdown
  • backend/tests/test_session.py: Update patches to mock get_files_directory

Usage

[features.spontaneous_file_upload]
files_dir = "/var/data/chainlit-uploads"

Relative paths (e.g. files_dir = "uploads") resolve from the app root.

Testing

All 35 session tests pass. Default behavior unchanged (.files directory).


Summary by cubic

Make the uploads directory configurable via config.toml and harden file handling. Defaults to .files; relative paths resolve from the app root.

  • New Features

    • Add files_dir to [features.spontaneous_file_upload] to override the uploads directory.
    • Resolve relative paths from CHAINLIT_APP_ROOT; absolute paths work as-is.
    • Use get_files_directory for session storage and server cleanup.
  • Bug Fixes

    • Guard against missing spontaneous_file_upload config.
    • Create upload dirs on demand with mkdir(parents=True) instead of at import.
    • Only delete uploads under APP_ROOT on shutdown (including the default .files).

Written for commit 475ac36. Summary will update on new commits.

Add files_dir option to [features.spontaneous_file_upload] in
config.toml. Relative paths are resolved from the app root. Defaults
to ".files" for backward compatibility.
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. backend Pertains to the Python backend. enhancement New feature or request labels Mar 1, 2026
Copy link
Copy Markdown
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.

3 issues found across 4 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/server.py">

<violation number="1" location="backend/chainlit/server.py:189">
P2: Shutdown cleanup now recursively deletes the user-configured files_dir without restricting it to an app-owned path, so setting files_dir to a shared or persistent directory can wipe arbitrary data on shutdown.</violation>
</file>

<file name="backend/chainlit/config.py">

<violation number="1" location="backend/chainlit/config.py:691">
P2: Upload directory is no longer created; get_files_directory returns a path without ensuring it exists, and callers mkdir only the session subdir without parents. On fresh installs/custom paths this can raise FileNotFoundError and break uploads.</violation>

<violation number="2" location="backend/chainlit/config.py:693">
P2: get_files_directory dereferences config.features.spontaneous_file_upload without guarding against it being None, which can raise AttributeError when the config omits the [features.spontaneous_file_upload] section.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread backend/chainlit/server.py
Comment thread backend/chainlit/config.py
Comment thread backend/chainlit/config.py Outdated
- Guard against None spontaneous_file_upload config
- Use mkdir(parents=True) for nested directory creation
- Only rmtree files under APP_ROOT on shutdown
- Fix ruff formatting in test_session.py
@Br1an67
Copy link
Copy Markdown
Contributor Author

Br1an67 commented Mar 9, 2026

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

Copy link
Copy Markdown
Contributor

@hayescode hayescode left a comment

Choose a reason for hiding this comment

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

Reviewed via Codex

LGTM.

@dokterbob dokterbob enabled auto-merge April 1, 2026 16:13
@hayescode
Copy link
Copy Markdown
Contributor

@Br1an67 please fix the failing CI then we should be good to merge!

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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make file uploads directory configurable

2 participants