fix(上传文件): 解决上传文件大小限制问题
This commit is contained in:
1 parent
9203a90637
commit
fc4631218b
3 files changed
+13
-3
No files matched your search
@@ -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'))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+5
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user