fix multipart/form-data decoding
This commit is contained in:
parent
c0f24eaf5d
commit
89cab66898
2 changed files with 42 additions and 10 deletions
|
|
@ -3,6 +3,8 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import fs from 'node:fs';
|
||||
import * as tmp from 'tmp';
|
||||
|
||||
export function createTemp(): Promise<[string, () => void]> {
|
||||
|
|
@ -27,3 +29,14 @@ export function createTempDir(): Promise<[string, () => void]> {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream): Promise<string> {
|
||||
const [filepath, cleanup] = await createTemp();
|
||||
try {
|
||||
await pipeline(stream, fs.createWriteStream(filepath));
|
||||
return filepath;
|
||||
} catch (e) {
|
||||
cleanup();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue