add the filename length limit (#5326)

This commit is contained in:
Jyong 2024-06-17 20:36:54 +08:00 committed by GitHub
parent 147a39b984
commit 07387e9586
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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'