UNPKG

2.88 kBTypeScriptView Raw
1import Macroable from '@poppinss/macroable';
2import type { FileJSON, FileUploadError, FileValidationOptions } from '../types.js';
3/**
4 * The file holds the meta/data for an uploaded file, along with
5 * an errors occurred during the upload process.
6 */
7export declare class MultipartFile extends Macroable {
8 #private;
9 /**
10 * A boolean to know if file is an instance of this class
11 * or not
12 */
13 isMultipartFile: true;
14 /**
15 * Field name is the name of the field
16 */
17 fieldName: string;
18 /**
19 * Client name is the file name on the user client
20 */
21 clientName: string;
22 /**
23 * The headers sent as part of the multipart request
24 */
25 headers: Record<string, any>;
26 /**
27 * File size in bytes
28 */
29 size: number;
30 /**
31 * The extname for the file.
32 */
33 extname?: string;
34 /**
35 * Upload errors
36 */
37 errors: FileUploadError[];
38 /**
39 * Type and subtype are extracted from the `content-type`
40 * header or from the file magic number
41 */
42 type?: string;
43 subtype?: string;
44 /**
45 * File path is only set after the move operation
46 */
47 filePath?: string;
48 /**
49 * File name is only set after the move operation. It is the relative
50 * path of the moved file
51 */
52 fileName?: string;
53 /**
54 * Tmp path, only exists when file is uploaded using the
55 * classic mode.
56 */
57 tmpPath?: string;
58 /**
59 * The file meta data
60 */
61 meta: any;
62 /**
63 * The state of the file
64 */
65 state: 'idle' | 'streaming' | 'consumed' | 'moved';
66 /**
67 * Whether or not the validations have been executed
68 */
69 get validated(): boolean;
70 /**
71 * A boolean to know if file has one or more errors
72 */
73 get isValid(): boolean;
74 /**
75 * Opposite of [[this.isValid]]
76 */
77 get hasErrors(): boolean;
78 /**
79 * The maximum file size limit
80 */
81 get sizeLimit(): number | string | undefined;
82 set sizeLimit(limit: number | string | undefined);
83 /**
84 * Extensions allowed
85 */
86 get allowedExtensions(): string[] | undefined;
87 set allowedExtensions(extensions: string[] | undefined);
88 constructor(data: {
89 fieldName: string;
90 clientName: string;
91 headers: any;
92 }, validationOptions: Partial<FileValidationOptions>);
93 /**
94 * Validate the file
95 */
96 validate(): void;
97 /**
98 * Mark file as moved
99 */
100 markAsMoved(fileName: string, filePath: string): void;
101 /**
102 * Moves the file to a given location. Multiple calls to the `move` method are allowed,
103 * incase you want to move a file to multiple locations.
104 */
105 move(location: string, options?: {
106 name?: string;
107 overwrite?: boolean;
108 }): Promise<void>;
109 /**
110 * Returns file JSON representation
111 */
112 toJSON(): FileJSON;
113}