Consolidateion of document upload API (#14106)

### What problem does this PR solve?

Consolidation WEB API & HTTP API for document upload

Before consolidation
Web API: POST /v1/document/upload
Http API - POST /api/v1/datasets/<dataset_id>/documents

After consolidation, Restful API -- POST
/api/v1/datasets/<dataset_id>/documents

### Type of change

- [x] Refactoring
This commit is contained in:
Jack
2026-04-15 11:27:43 +08:00
committed by GitHub
parent e1dede1366
commit bc5f78996b
13 changed files with 339 additions and 319 deletions

View File

@ -332,7 +332,9 @@ def batch_create_datasets(auth, num):
# DOCUMENT APP
def upload_documents(auth, payload=None, files_path=None, *, filename_override=None):
url = f"{HOST_ADDRESS}{DOCUMENT_APP_URL}/upload"
# New endpoint: /api/v1/datasets/{kb_id}/documents
kb_id = payload.get("kb_id") if payload else None
url = f"{HOST_ADDRESS}/api/{VERSION}/datasets/{kb_id}/documents"
if files_path is None:
files_path = []
@ -340,9 +342,11 @@ def upload_documents(auth, payload=None, files_path=None, *, filename_override=N
fields = []
file_objects = []
try:
# Note: kb_id is now in the URL path, not in the form data
if payload:
for k, v in payload.items():
fields.append((k, str(v)))
if k != "kb_id": # Skip kb_id as it's in the URL
fields.append((k, str(v)))
for fp in files_path:
p = Path(fp)