|
|
@@ -7,6 +7,7 @@
|
|
|
*/
|
|
|
import { getToken } from '@/core/utils/auth';
|
|
|
import { downloadByData } from '@/core/utils/file/download';
|
|
|
+import { defHttp } from '@/core/utils/http/axios';
|
|
|
import { resolveApiUrl } from '../utils/constants';
|
|
|
import { aiHttp } from './http';
|
|
|
import type { KnowledgeBase, KnowledgeDoc, SaveKnowledgeBaseParams } from './types';
|
|
|
@@ -41,18 +42,18 @@ export function listMyDocs(kbId: string): Promise<KnowledgeDoc[]> {
|
|
|
* 列表轮询看 indexStatus)。
|
|
|
*/
|
|
|
export async function uploadDoc(kbId: string, file: File): Promise<KnowledgeDoc> {
|
|
|
- const form = new FormData();
|
|
|
- form.append('file', file);
|
|
|
- const res: any = await aiHttp.request<any>(
|
|
|
+ // 必须走 defHttp.uploadFile:普通 post 发 FormData 会被实例默认的
|
|
|
+ // content-type: application/x-www-form-urlencoded 覆盖,后端判成
|
|
|
+ // 「Current request is not a multipart request」直接 500。
|
|
|
+ const res: any = await defHttp.uploadFile<any>(
|
|
|
{
|
|
|
- url: `/knowledge-bases/${kbId}/docs`,
|
|
|
- method: 'POST',
|
|
|
- data: form,
|
|
|
- // multipart 让 axios 自设 boundary,不手动写 content-type
|
|
|
+ url: resolveApiUrl(`/knowledge-bases/${kbId}/docs`),
|
|
|
+ // 提取在请求内完成(扫描件 OCR / 音视频转写),与对话附件一样给 10 分钟
|
|
|
timeout: 10 * 60 * 1000,
|
|
|
},
|
|
|
+ { name: 'file', file, filename: file.name },
|
|
|
);
|
|
|
- return res as KnowledgeDoc;
|
|
|
+ return (res?.data?.data ?? res?.data ?? res) as KnowledgeDoc;
|
|
|
}
|
|
|
|
|
|
/** 删除文档(仅上传者) */
|