-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: AlipayFormData 支持文件流和文件内容上传文件 (#134)
fix: 设置文件上传分片 chunk 最小为 2MB, 避开 OpenAPI 接入层的 chunk 数量限制 基于 node-modules/formstream#26 实现 closes #130 closes #135
- Loading branch information
Showing
8 changed files
with
258 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
// import { statSync } from 'node:fs'; | ||
import FormStream from 'formstream'; | ||
|
||
export interface AlipayFormStreamOptions { | ||
/** min chunk size to emit data event */ | ||
minChunkSize?: number; | ||
} | ||
|
||
export class AlipayFormStream extends FormStream { | ||
// 覆盖 file 方法,由于 OpenAPI 文件上传需要强制设置 content-length,所以需要增加一次同步文件 io 来实现此功能 | ||
// https://github.com/node-modules/formstream/blob/master/lib/formstream.js#L119 | ||
// file(name: string, filepath: string, filename: string) { | ||
// const size = statSync(filepath).size; | ||
// return super.file(name, filepath, filename, size); | ||
// } | ||
constructor(options?: AlipayFormStreamOptions) { | ||
super({ | ||
// set default minChunkSize to 2MB | ||
minChunkSize: 1024 * 1024 * 2, | ||
...options, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.