Docs/DTOs
@fileUploadProperty
Marks a DTO property as a file upload field with MIME type and size validation.
TypeScript
import { fileUploadProperty } from 'alado';
export class UserFilesDto {
@fileUploadProperty({
mimetypes: [
'image/png',
'image/jpeg',
],
maxSize: 2 * 1024 * 1024, // 2MB in bytes
required: true,
maxSizeError: {
statusCode: 413,
message: 'File must not exceed 2MB',
},
mimetypeError: {
statusCode: 415,
message: 'Only PNG and JPEG images are allowed',
},
requiredError: {
statusCode: 400,
message: 'Avatar file is required',
},
})
avatar: string = '/path/to/avatar.png';
}The MIME type of an upload is whatever the client declares, so for types with a fixed signature (image/png, image/jpeg, image/gif, image/webp, application/pdf and application/zip) the first bytes of the file must match it too, or the request gets mimetypeError. Types without a signature (plain text, CSV, JSON, SVG…) are only checked against mimetypes. Set verifyContent: false on a field to skip the content check.
Never serve an uploaded file back with the client's MIME type without your own check: an "image" can be an HTML page.