浏览代码

add the filename length limit (#5326)

Jyong 10 月之前
父节点
当前提交
07387e9586
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      api/services/file_service.py

+ 6 - 1
api/services/file_service.py

@@ -31,7 +31,10 @@ class FileService:
 
     @staticmethod
     def upload_file(file: FileStorage, user: Union[Account, EndUser], only_image: bool = False) -> UploadFile:
+        filename = file.filename
         extension = file.filename.split('.')[-1]
+        if len(filename) > 200:
+            filename = filename.split('.')[0][:200] + '.' + extension
         etl_type = current_app.config['ETL_TYPE']
         allowed_extensions = UNSTRUSTURED_ALLOWED_EXTENSIONS + IMAGE_EXTENSIONS if etl_type == 'Unstructured' \
             else ALLOWED_EXTENSIONS + IMAGE_EXTENSIONS
@@ -75,7 +78,7 @@ class FileService:
             tenant_id=current_tenant_id,
             storage_type=config['STORAGE_TYPE'],
             key=file_key,
-            name=file.filename,
+            name=filename,
             size=file_size,
             extension=extension,
             mime_type=file.mimetype,
@@ -93,6 +96,8 @@ class FileService:
 
     @staticmethod
     def upload_text(text: str, text_name: str) -> UploadFile:
+        if len(text_name) > 200:
+            text_name = text_name[:200]
         # user uuid as file name
         file_uuid = str(uuid.uuid4())
         file_key = 'upload_files/' + current_user.current_tenant_id + '/' + file_uuid + '.txt'