mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-04-21 13:19:43 +08:00
add the filename length limit (#5326)
This commit is contained in:
parent
147a39b984
commit
07387e9586
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user