Skip to content

Commit

Permalink
docs(validations/files): Add example for custom file validator
Browse files Browse the repository at this point in the history
  • Loading branch information
SngGyanendra committed Nov 6, 2024
1 parent e014e7e commit cd10d70
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions content/techniques/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export class FileSizeValidationPipe implements PipeTransform {
}
```

This can be used in conjunction with the `FileInterceptor` as follows:

```typescript
@Post('file')
@UseInterceptors(FileInterceptor('file'))
uploadFileAndValidate(@UploadedFile(
new FileSizeValidationPipe(),
// all other validators here
) file: Express.Multer.File, ) {
return file;
}
```

Nest provides a built-in pipe to handle common use cases and facilitate/standardize the addition of new ones. This pipe is called `ParseFilePipe`, and you can use it as follows:

```typescript
Expand Down

0 comments on commit cd10d70

Please sign in to comment.