diff --git a/backend/app/core/config/settings.py b/backend/app/core/config/settings.py index 65d966c9..f588f693 100644 --- a/backend/app/core/config/settings.py +++ b/backend/app/core/config/settings.py @@ -78,6 +78,8 @@ def _backend_path(env_key: str, *parts: str) -> str: class Config: SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = os.getenv('SECRET_KEY') + # 配置最大上传文件大小(200MB) + MAX_CONTENT_LENGTH = 200 * 1024 * 1024 KB_STORAGE_ROOT = _data_path('KB_STORAGE_ROOT', 'kb') KB_TASK_EXECUTION_MODE = os.getenv('KB_TASK_EXECUTION_MODE', 'worker').strip().lower() KB_WORKER_POLL_SECONDS = float(os.getenv('KB_WORKER_POLL_SECONDS', '2')) diff --git a/backend/app/services/admin/guide_service.py b/backend/app/services/admin/guide_service.py index 23d4af1d..13e5fbbd 100644 --- a/backend/app/services/admin/guide_service.py +++ b/backend/app/services/admin/guide_service.py @@ -83,8 +83,12 @@ def upload_guide_file(file_storage: FileStorage | None) -> dict: if not file_storage or file_storage.filename == '': raise ValidationError('No selected file' if file_storage else 'No file part') content_type = file_storage.content_type - file_size = len(file_storage.read()) - file_storage.seek(0) + + # 更高效地获取文件大小,不一次性读取全部内容到内存 + file_storage.seek(0, 2) # 移动到文件末尾 + file_size = file_storage.tell() # 获取当前位置(即文件大小) + file_storage.seek(0) # 重置到文件开头 + try: object_name = minio_service.upload_file(file_storage, file_storage.filename, content_type, file_size) return { diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 04e607cd..d5182a56 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -1,7 +1,9 @@ server { listen 80; server_name localhost; - client_max_body_size 100m; + client_max_body_size 200m; + client_body_timeout 300s; + send_timeout 300s; resolver 127.0.0.11 valid=30s ipv6=off; resolver_timeout 5s; @@ -28,5 +30,7 @@ server { proxy_buffering off; proxy_cache off; proxy_read_timeout 300s; + proxy_connect_timeout 75s; + proxy_send_timeout 300s; } }