|
@@ -5,13 +5,14 @@ class DocumentService:
|
|
|
self.http_client = http_client
|
|
self.http_client = http_client
|
|
|
|
|
|
|
|
def upload_document(self, dataset_id: str, file_path: str) -> List[Dict[str, Any]]:
|
|
def upload_document(self, dataset_id: str, file_path: str) -> List[Dict[str, Any]]:
|
|
|
|
|
+ import os
|
|
|
endpoint = f"/api/v1/datasets/{dataset_id}/documents"
|
|
endpoint = f"/api/v1/datasets/{dataset_id}/documents"
|
|
|
|
|
|
|
|
with open(file_path, 'rb') as f:
|
|
with open(file_path, 'rb') as f:
|
|
|
- files = {'file': (file_path.split('/')[-1], f)}
|
|
|
|
|
- headers = {'Content-Type': 'multipart/form-data'}
|
|
|
|
|
-
|
|
|
|
|
- response = self.http_client.post(endpoint, files=files, headers=headers)
|
|
|
|
|
|
|
+ # 使用os.path.basename获取文件名,兼容Windows和Linux
|
|
|
|
|
+ files = {'file': (os.path.basename(file_path), f)}
|
|
|
|
|
+ # 不设置Content-Type头,让requests库自动生成正确的multipart/form-data头
|
|
|
|
|
+ response = self.http_client.post(endpoint, files=files)
|
|
|
|
|
|
|
|
if response.get("code") == 0 and response.get("data"):
|
|
if response.get("code") == 0 and response.get("data"):
|
|
|
return response["data"]
|
|
return response["data"]
|