-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/4752 file validators pipe #9718
Feature/4752 file validators pipe #9718
Conversation
fix import to relative path, the alias was causing cyclic references
add curly braces to if statement for consistency
add tests for parse file pipe builder and refactor associated classes
Pull Request Test Coverage Report for Build 951dfe3d-110c-4cb2-a7e2-985cea4aced1
💛 - Coveralls |
That sounds great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good work, we really needed this. I'm already looking forward to using this validator 😀
/** | ||
* Interface describing FileValidators, which can be added to a {@link ParseFilePipe}. | ||
*/ | ||
export abstract class FileValidator<TValidationOptions = Record<string, any>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent code structure, it was very well thought out in that aspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Hebert, although this still lacks promise handling, so I'll have to add that before merging
Once we have e2e tests in place, would you like to create a PR to the docs @thiagomini (adding this pipe to the list of available pipes etc, and then describing these validators in the File Upload chapter) |
Sure! I'll do that 👍 |
add async validation feature
add partial mimetype check
add test using file parse pipe
@kamilmysliwiec added async validation feature here, e2e tests and started creating the Docs PR: I would appreciate some review on these as well to guarantee it can be well understood. |
lgtm |
@kamilmysliwiec @thiagomini Can you support regex instead OR in addition to the current type check? Excel files for example can have multiple options for mimetype |
I can add that support in a new PR |
@thiagomini I'd love to |
created PR to handle it and also added some useful docs about the reliability of this pipe. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
We don't have validation options out of the box for the
@UploadedFile()
decorator.Issue Number: #4752
What is the new behavior?
We can use some default validators using pipes:
MaxFileSizeValidator
andFileTypeValidator
. Also, we can pass our own validators if they follow theFileValidator
interface.Does this PR introduce a breaking change?
Other information
This still needs tests to verify if it's actually working with files (e2e tests maybe?)
This is a continuation of a previous, stale PR