From 92ab338640a1b1107657188cc8b27cfdd80d74ea Mon Sep 17 00:00:00 2001 From: Pleasure1234 <3196812536@qq.com> Date: Wed, 27 Aug 2025 12:07:57 +0800 Subject: [PATCH] fix: remove Content-Length header and add duplex option in putFile (#9576) The putFile method no longer sets the Content-Length header and now includes the duplex: 'half' option in the net.fetch call. This change ensures compatibility with streaming uploads and the requirements of net.fetch. --- .../knowledge/preprocess/Doc2xPreprocessProvider.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/knowledge/preprocess/Doc2xPreprocessProvider.ts b/src/main/knowledge/preprocess/Doc2xPreprocessProvider.ts index 834ff2f27e..6708e8f938 100644 --- a/src/main/knowledge/preprocess/Doc2xPreprocessProvider.ts +++ b/src/main/knowledge/preprocess/Doc2xPreprocessProvider.ts @@ -201,20 +201,14 @@ export default class Doc2xPreprocessProvider extends BasePreprocessProvider { */ private async putFile(filePath: string, url: string): Promise { try { - // 获取文件大小用于设置 Content-Length - const stats = await fs.promises.stat(filePath) - const fileSize = stats.size - // 创建可读流 const fileStream = fs.createReadStream(filePath) const response = await net.fetch(url, { method: 'PUT', body: fileStream as any, // TypeScript 类型转换,net.fetch 支持 ReadableStream - headers: { - 'Content-Length': fileSize.toString() - } - }) + duplex: 'half' + } as any) // TypeScript 类型转换,net.fetch 需要 duplex 选项 if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`)