Skip to content

Commit 00a0cf2

Browse files
authored
docs: clarify FileTypeValidator warning
add more details about file type detection by FileTypeValidator
1 parent 67f1c99 commit 00a0cf2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

content/techniques/file-upload.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export abstract class FileValidator<TValidationOptions = Record<string, any>> {
120120
- `MaxFileSizeValidator` - Checks if a given file's size is less than the provided value (measured in `bytes`)
121121
- `FileTypeValidator` - Checks if a given file's mime-type matches the given value.
122122

123-
> warning **Warning** The [FileTypeValidator](https://github.com/nestjs/nest/blob/master/packages/common/pipes/file/file-type.validator.ts) class uses a naive implementation to verify the incoming file's type. Consider using a custom implementation (like checking the file's [magic number](https://www.ibm.com/support/pages/what-magic-number)) if your app requires a safer solution.
123+
> warning **Warning** To verify file type, [FileTypeValidator](https://github.com/nestjs/nest/blob/master/packages/common/pipes/file/file-type.validator.ts) class uses the type as detected by multer. By default, multer derives file type from file extension on user's device. However, it does not check actual file contents. As files can be renamed to arbitraty extensions, consider using a custom implementation (like checking the file's [magic number](https://www.ibm.com/support/pages/what-magic-number)) if your app requires a safer solution.
124124
125125
To understand how these can be used in conjunction with the beforementioned `FileParsePipe`, we'll use an altered snippet of the last presented example:
126126

0 commit comments

Comments
 (0)