Browse Source

Update upload filename length limit from 128 to 256, which is aligned with os (#7971)

### What problem does this PR solve?

Change filename length limit from 128 to 256

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
tags/v0.19.1
Jin Hai 5 months ago
parent
commit
31f4d44c73
No account linked to committer's email address

+ 1
- 1
api/apps/kb_app.py View File

return get_data_error_result(message="Dataset name must be string.") return get_data_error_result(message="Dataset name must be string.")
if dataset_name == "": if dataset_name == "":
return get_data_error_result(message="Dataset name can't be empty.") return get_data_error_result(message="Dataset name can't be empty.")
if len(dataset_name) >= DATASET_NAME_LIMIT:
if len(dataset_name.encode("utf-8")) >= DATASET_NAME_LIMIT:
return get_data_error_result( return get_data_error_result(
message=f"Dataset name length is {len(dataset_name)} which is large than {DATASET_NAME_LIMIT}") message=f"Dataset name length is {len(dataset_name)} which is large than {DATASET_NAME_LIMIT}")



+ 1
- 0
api/constants.py View File

REQUEST_MAX_WAIT_SEC = 300 REQUEST_MAX_WAIT_SEC = 300


DATASET_NAME_LIMIT = 128 DATASET_NAME_LIMIT = 128
FILE_NAME_LEN_LIMIT = 256

+ 2
- 2
api/db/services/file_service.py View File

from api.utils import get_uuid from api.utils import get_uuid
from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img
from rag.utils.storage_factory import STORAGE_IMPL from rag.utils.storage_factory import STORAGE_IMPL
from api.constants import FILE_NAME_LEN_LIMIT


class FileService(CommonService): class FileService(CommonService):
# Service class for managing file operations and storage # Service class for managing file operations and storage
MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0)) MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0))
if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(kb.tenant_id) >= MAX_FILE_NUM_PER_USER: if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(kb.tenant_id) >= MAX_FILE_NUM_PER_USER:
raise RuntimeError("Exceed the maximum file number of a free user!") raise RuntimeError("Exceed the maximum file number of a free user!")
if len(file.filename.encode("utf-8")) >= 128:
if len(file.filename.encode("utf-8")) >= FILE_NAME_LEN_LIMIT:
raise RuntimeError("Exceed the maximum length of file name!") raise RuntimeError("Exceed the maximum length of file name!")


filename = duplicate_name(DocumentService.query, name=file.filename, kb_id=kb.id) filename = duplicate_name(DocumentService.query, name=file.filename, kb_id=kb.id)

+ 1
- 1
sdk/python/test/test_frontend_api/test_dataset.py View File



long_string = "" long_string = ""


while len(long_string) <= DATASET_NAME_LIMIT:
while len(long_string.encode("utf-8")) <= DATASET_NAME_LIMIT:
long_string += random.choice(string.ascii_letters + string.digits) long_string += random.choice(string.ascii_letters + string.digits)


res = create_dataset(get_auth, long_string) res = create_dataset(get_auth, long_string)

Loading…
Cancel
Save