UNPKG

1.93 kBTypeScriptView Raw
1import { IncomingMessage } from "http";
2import { EmitData, EventData, Fields, File, Files, Options, Part, PluginFunction, DefaultOptions } from "./";
3declare class IncomingForm {
4 static readonly DEFAULT_OPTIONS: DefaultOptions;
5 constructor(options?: Partial<Options>);
6
7 /**
8 * Parses an incoming Node.js request containing form data. If callback is provided, all fields
9 * and files are collected and passed to the callback.
10 *
11 * @link https://github.com/node-formidable/formidable#parserequest-callback
12 */
13 parse(request: IncomingMessage, callback: (err: any, fields: Fields, files: Files) => void): void;
14
15 once(name: "end", callback: () => void): void;
16 once(name: "error", callback: (err: any) => void): void;
17
18 on(name: "data", callback: (data: EventData) => void): void;
19 on(name: "error", callback: (err: any) => void): void;
20 on(name: "field", callback: (name: string, value: string) => void): void;
21 on(name: "fileBegin" | "file", callback: (formName: string, file: File) => void): void;
22 on(name: "progress", callback: (bytesReceived: number, bytesExpected: number) => void): void;
23 on(name: string, callback: () => void): void;
24
25 emit(name: "data", data: EmitData): void;
26
27 /**
28 * A method that allows you to extend the Formidable library. By default we include 4 plugins,
29 * which essentially are adapters to plug the different built-in parsers.
30 *
31 * @link https://github.com/node-formidable/formidable#useplugin-plugin
32 */
33 use(plugin: PluginFunction): void;
34
35 /**
36 * If you want to use Formidable to only handle certain parts for you, you can do something
37 * similar. Or see #387 for inspiration, you can for example validate the mime-type.
38 *
39 * @link https://github.com/node-formidable/formidable#formonpart
40 */
41 onPart(part: Part): void;
42
43 handlePart(part: Part): void;
44}
45
46export = IncomingForm;