- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ImageField
missing validation?
#4088
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
Comments
Do you check the mimetype? |
How would I go about this? I tried adding constraints to my entity, but I could not make |
You can do this with these annotations in yours entities:
|
I have this (but using vich)
|
and my field def:
|
Both very helpful, thanks (apologies for the delayed response, I had to table this project for a while)! I was indeed already using Vich before, so I don't really mind to keep using it, as I found it to work well for me, and I got it to work for single images just fine. Any ideas on how to make it work for multiple images @parijke? I'm thinking I might need to go the extra step here and do an |
This PR was squashed before being merged into the 4.x branch. Discussion ---------- [ImageField] Support constraint validation Fixes #5227 and #4088 Currently, it is not possible to properly validate images uploaded with the `ImageField` using Symfony constraints. This is because the `constraints` option is applied to both the parent field (returning a `string`) and the underlying `FileType` field (returning an `UploadedFile`) resulting in unexpected validation errors. This PR adds a new `setFileConstraints` method to the `ImageField` to apply constraints to the `FileType` field only. By default, I also applied the [`Image`](https://symfony.com/doc/current/reference/constraints/Image.html) constraint on the `ImageField`. Usage example: ``` php use Symfony\Component\Validator\Constraints\Image; // Validate that file is an image by default ImageField::new('logo', 'Logo'), // Set custom validation constraints ImageField::new('logo', 'Logo')->setFileConstraints(new Image(maxSize: '100k')), ``` Commits ------- 76a9e9d [ImageField] Support constraint validation
Closing as fixed in #6258. |
Describe the bug
I'm using the
ImageField
like so:This works, however I'm able to also upload files that are not images. I would be fine adding this validation manually, but I haven't really found a way to do so
To Reproduce
Install EA 3.2.0, use an
ImageField
like described above, and upload a file that's not an imageThe text was updated successfully, but these errors were encountered: