Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

add the filename length limit (#5326)

Jyong07387e9586c1
diff --git a/api/services/file_service.py b/api/services/file_service.py
index f9df21f544b..aad477f8a01 100644
--- a/api/services/file_service.py
+++ b/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'