Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

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

Jin Hai31f4d44c73e7
diff --git a/api/apps/kb_app.py b/api/apps/kb_app.py
index 206af56c12..3971dfdf0e 100644
--- a/api/apps/kb_app.py
+++ b/api/apps/kb_app.py
@@ -47,7 +47,7 @@ def create():
return get_data_error_result(message="Dataset name must be string.")
if dataset_name == "":
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(
message=f"Dataset name length is {len(dataset_name)} which is large than {DATASET_NAME_LIMIT}")
diff --git a/api/constants.py b/api/constants.py
index e6a97e2c1b..f5de6d98b3 100644
--- a/api/constants.py
+++ b/api/constants.py
@@ -25,3 +25,4 @@ REQUEST_WAIT_SEC = 2
REQUEST_MAX_WAIT_SEC = 300
DATASET_NAME_LIMIT = 128
+FILE_NAME_LEN_LIMIT = 256
diff --git a/api/db/services/file_service.py b/api/db/services/file_service.py
index 803164f9ee..664cd1bdbe 100644
--- a/api/db/services/file_service.py
+++ b/api/db/services/file_service.py
@@ -30,7 +30,7 @@ from api.db.services.file2document_service import File2DocumentService
from api.utils import get_uuid
from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img
from rag.utils.storage_factory import STORAGE_IMPL
-
+from api.constants import FILE_NAME_LEN_LIMIT
class FileService(CommonService):
# Service class for managing file operations and storage
@@ -412,7 +412,7 @@ class FileService(CommonService):
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:
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!")
filename = duplicate_name(DocumentService.query, name=file.filename, kb_id=kb.id)
diff --git a/sdk/python/test/test_frontend_api/test_dataset.py b/sdk/python/test/test_frontend_api/test_dataset.py
index 3baaf4e8ca..c60dc4d0c0 100644
--- a/sdk/python/test/test_frontend_api/test_dataset.py
+++ b/sdk/python/test/test_frontend_api/test_dataset.py
@@ -108,7 +108,7 @@ def test_invalid_name_dataset(get_auth):
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)
res = create_dataset(get_auth, long_string)