Skip to content

Commit e2d283f

Browse files
committed
Update upload filename length limit from 128 to 256, which is aligned with os
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent 62de535 commit e2d283f

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

api/apps/kb_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def create():
4747
return get_data_error_result(message="Dataset name must be string.")
4848
if dataset_name == "":
4949
return get_data_error_result(message="Dataset name can't be empty.")
50-
if len(dataset_name) >= DATASET_NAME_LIMIT:
50+
if len(dataset_name.encode("utf-8")) >= DATASET_NAME_LIMIT:
5151
return get_data_error_result(
5252
message=f"Dataset name length is {len(dataset_name)} which is large than {DATASET_NAME_LIMIT}")
5353

api/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
REQUEST_MAX_WAIT_SEC = 300
2626

2727
DATASET_NAME_LIMIT = 128
28+
FILE_NAME_LEN_LIMIT = 256

api/db/services/file_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from api.utils import get_uuid
3131
from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img
3232
from rag.utils.storage_factory import STORAGE_IMPL
33-
33+
from api.constants import FILE_NAME_LEN_LIMIT
3434

3535
class FileService(CommonService):
3636
# Service class for managing file operations and storage
@@ -412,7 +412,7 @@ def upload_document(self, kb, file_objs, user_id):
412412
MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0))
413413
if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(kb.tenant_id) >= MAX_FILE_NUM_PER_USER:
414414
raise RuntimeError("Exceed the maximum file number of a free user!")
415-
if len(file.filename.encode("utf-8")) >= 128:
415+
if len(file.filename.encode("utf-8")) >= FILE_NAME_LEN_LIMIT:
416416
raise RuntimeError("Exceed the maximum length of file name!")
417417

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

sdk/python/test/test_frontend_api/test_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_invalid_name_dataset(get_auth):
108108

109109
long_string = ""
110110

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

114114
res = create_dataset(get_auth, long_string)

0 commit comments

Comments
 (0)