1 |
|
2 | import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
3 | import { MultipartContract, PartHandler as PartHandlerType } from '@ioc:Adonis/Core/BodyParser';
|
4 | import { DriveManagerContract } from '@ioc:Adonis/Core/Drive';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export declare class Multipart implements MultipartContract {
|
11 | private ctx;
|
12 | private config;
|
13 | private drive;
|
14 | |
15 |
|
16 |
|
17 | private handlers;
|
18 | |
19 |
|
20 |
|
21 | private fields;
|
22 | |
23 |
|
24 |
|
25 |
|
26 | private files;
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 | private pendingHandlers;
|
33 | |
34 |
|
35 |
|
36 | private form;
|
37 | |
38 |
|
39 |
|
40 |
|
41 | private upperLimit?;
|
42 | |
43 |
|
44 |
|
45 | private processedBytes;
|
46 | |
47 |
|
48 |
|
49 | state: 'idle' | 'processing' | 'error' | 'success';
|
50 | constructor(ctx: HttpContextContract, config: Partial<{
|
51 | limit: string | number;
|
52 | maxFields: number;
|
53 | convertEmptyStringsToNull: boolean;
|
54 | }>, drive: DriveManagerContract);
|
55 | /**
|
56 | * Returns a boolean telling whether all streams have been
|
57 | * consumed along with all handlers execution
|
58 | */
|
59 | private isClosed;
|
60 | /**
|
61 | * Removes array like expression from the part name to
|
62 | * find the handler
|
63 | */
|
64 | private getHandlerName;
|
65 | /**
|
66 | * Validates and returns an error when upper limit is defined and
|
67 | * processed bytes is over the upper limit
|
68 | */
|
69 | private validateProcessedBytes;
|
70 | /**
|
71 | * Handles a given part by invoking it's handler or
|
72 | * by resuming the part, if there is no defined
|
73 | * handler
|
74 | */
|
75 | private handlePart;
|
76 | /**
|
77 | * Record the fields inside multipart contract
|
78 | */
|
79 | private handleField;
|
80 | /**
|
81 | * Processes the user config and computes the `upperLimit` value from
|
82 | * it.
|
83 | */
|
84 | private processConfig;
|
85 | /**
|
86 | * Mark the process as finished
|
87 | */
|
88 | private finish;
|
89 | /**
|
90 | * Attach handler for a given file. To handle all files, you
|
91 | * can attach a wildcard handler.
|
92 | *
|
93 | * @example
|
94 | * ```ts
|
95 | * multipart.onFile('package', {}, async (stream) => {
|
96 | * })
|
97 | *
|
98 | * multipart.onFile('*', {}, async (stream) => {
|
99 | * })
|
100 | * ```
|
101 | */
|
102 | onFile(name: string, options: Parameters<MultipartContract['onFile']>[1], handler: PartHandlerType): this;
|
103 | /**
|
104 | * Abort request by emitting error
|
105 | */
|
106 | abort(error: any): void;
|
107 | /**
|
108 | * Process the request by going all the file and field
|
109 | * streams.
|
110 | */
|
111 | process(config?: Parameters<MultipartContract['process']>[0]): Promise<void>;
|
112 | }
|