UNPKG

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