mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +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> {
|
private async putFile(filePath: string, url: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// 获取文件大小用于设置 Content-Length
|
|
||||||
const stats = await fs.promises.stat(filePath)
|
|
||||||
const fileSize = stats.size
|
|
||||||
|
|
||||||
// 创建可读流
|
// 创建可读流
|
||||||
const fileStream = fs.createReadStream(filePath)
|
const fileStream = fs.createReadStream(filePath)
|
||||||
|
|
||||||
const response = await net.fetch(url, {
|
const response = await net.fetch(url, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: fileStream as any, // TypeScript 类型转换,net.fetch 支持 ReadableStream
|
body: fileStream as any, // TypeScript 类型转换,net.fetch 支持 ReadableStream
|
||||||
headers: {
|
duplex: 'half'
|
||||||
'Content-Length': fileSize.toString()
|
} as any) // TypeScript 类型转换,net.fetch 需要 duplex 选项
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user