Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add site setting upload_max_body_size #497

Merged
merged 8 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make the file size humam-readble
sszgwdk committed Dec 13, 2024
commit 49e3d2b2d9e35d725345ce9d1ad1c045b58b2247
7 changes: 4 additions & 3 deletions backend/app/api/admin_routes/upload.py
Original file line number Diff line number Diff line change
@@ -34,12 +34,13 @@ def upload_files(
status_code=status.HTTP_400_BAD_REQUEST,
detail="File name cannot be empty",
)
if SiteSetting.setting_exists("upload_max_body_size"):
sys_upload_max_body_size = SiteSetting.get_setting("upload_max_body_size")
sys_upload_max_body_size = SiteSetting.upload_max_body_size
if sys_upload_max_body_size:
if file.size > sys_upload_max_body_size:
max_body_size_in_mb = sys_upload_max_body_size / 1024 / 1024
raise HTTPException(
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
detail=f"File size({file.size}) exceeds maximum allowed size({sys_upload_max_body_size})",
detail=f"File size({file.size} bytes) exceeds maximum allowed size({sys_upload_max_body_size} bytes)",
)

file_ext = os.path.splitext(file.filename)[1].lower()
4 changes: 2 additions & 2 deletions backend/app/site_settings/default_settings.yml
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ chat:

upload:
upload_max_body_size:
default: 10485760
default: 10485760 # 10MB
data_type: int
description: "Max body size of upload file."
description: "Max body size(in bytes) of upload file."
client: true