feat: make file uploads directory configurable via config.toml#2815
Open
Br1an67 wants to merge 3 commits intoChainlit:mainfrom
Open
feat: make file uploads directory configurable via config.toml#2815Br1an67 wants to merge 3 commits intoChainlit:mainfrom
Br1an67 wants to merge 3 commits intoChainlit:mainfrom
Conversation
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.
Contributor
There was a problem hiding this comment.
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.
- 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
Contributor
Author
|
Hi — just a gentle bump on this. Happy to make any changes if needed! |
hayescode
approved these changes
Apr 1, 2026
Contributor
hayescode
left a comment
There was a problem hiding this comment.
Reviewed via Codex
LGTM.
Contributor
|
@Br1an67 please fix the failing CI then we should be good to merge! |
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
files_diroption to[features.spontaneous_file_upload]in config.toml to override the default.filesdirectory.Closes #2155
Why
The
.filesdirectory is hardcoded, which is problematic when Chainlit runs in environments where the user doesn't control the app directory.Changes
backend/chainlit/config.py: Addfiles_dir: str = ".files"toSpontaneousFileUploadFeature, add it to TOML template, replace module-levelFILES_DIRECTORYwithget_files_directory()function that resolves relative paths fromAPP_ROOTbackend/chainlit/session.py: Useget_files_directory()instead ofFILES_DIRECTORYbackend/chainlit/server.py: Useget_files_directory()for cleanup on shutdownbackend/tests/test_session.py: Update patches to mockget_files_directoryUsage
Relative paths (e.g.
files_dir = "uploads") resolve from the app root.Testing
All 35 session tests pass. Default behavior unchanged (
.filesdirectory).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
Bug Fixes
Written for commit 475ac36. Summary will update on new commits.