Bläddra i källkod

add the filename length limit (#5326)

tags/0.6.12
Jyong 1 år sedan
förälder
incheckning
07387e9586
Inget konto är kopplat till bidragsgivarens mejladress
1 ändrade filer med 6 tillägg och 1 borttagningar
  1. 6
    1
      api/services/file_service.py

+ 6
- 1
api/services/file_service.py Visa fil

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

Laddar…
Avbryt
Spara