mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
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.
This commit is contained in:
parent
f273621082
commit
92ab338640
@ -201,20 +201,14 @@ export default class Doc2xPreprocessProvider extends BasePreprocessProvider {
|
||||
*/
|
||||
private async putFile(filePath: string, url: string): Promise<void> {
|
||||
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}`)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user