NestJS provides ParseFilePipe with built-in MaxFileSizeValidator and FileTypeValidator. Custom validators extend the abstract FileValidator class and implement isValid() and buildErrorMessage(). Pass an array of validator instances to ParseFilePipe's validators option.
MaxFileSizeValidator checks file.size in bytes — multiply MB by 1024 * 1024.
FileTypeValidator accepts a regex matched against file.mimetype — not the file extension.
Custom FileValidator extends the abstract base class and implements isValid() and buildErrorMessage().
isValid() can be async — useful for reading file headers or dimensions from the buffer.
errorHttpStatusCode defaults to 400 — use HttpStatus.UNPROCESSABLE_ENTITY (422) for semantic correctness.
fileIsRequired: false makes the pipe pass through when no file is provided.