UNPKG

1.46 kBTypeScriptView Raw
1import type { HttpContext } from '@adonisjs/http-server';
2import type { FileValidationOptions, PartHandler as PartHandlerType } from '../types.js';
3/**
4 * Multipart class offers a low level API to interact the incoming
5 * HTTP request data as a stream. This makes it super easy to
6 * write files to s3 without saving them to the disk first.
7 */
8export declare class Multipart {
9 #private;
10 /**
11 * The current state of the multipart form handler
12 */
13 state: 'idle' | 'processing' | 'error' | 'success';
14 constructor(ctx: HttpContext, config?: Partial<{
15 limit: string | number;
16 fieldsLimit: string | number;
17 maxFields: number;
18 convertEmptyStringsToNull: boolean;
19 }>);
20 /**
21 * Attach handler for a given file. To handle all files, you
22 * can attach a wildcard handler.
23 *
24 * @example
25 * ```ts
26 * multipart.onFile('package', {}, async (stream) => {
27 * })
28 *
29 * multipart.onFile('*', {}, async (stream) => {
30 * })
31 * ```
32 */
33 onFile(name: string, options: Partial<FileValidationOptions & {
34 deferValidations: boolean;
35 }>, handler: PartHandlerType): this;
36 /**
37 * Abort request by emitting error
38 */
39 abort(error: any): void;
40 /**
41 * Process the request by going all the file and field
42 * streams.
43 */
44 process(config?: Partial<{
45 limit: string | number;
46 maxFields: number;
47 }>): Promise<void>;
48}