- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Describe the bug
I'm using the ImageField
like so:
ImageField::new('avatar')
->setUploadDir('public/uploads/avatars/')
->setBasePath('uploads/avatars')
->setUploadedFileNamePattern('[year]-[month]-[day]-[contenthash].[extension]')
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 image
Activity
parijke commentedon Dec 30, 2020
Do you check the mimetype?
lauraseidler commentedon Jan 4, 2021
How would I go about this? I tried adding constraints to my entity, but I could not make
File
orImage
constraints work, since the field only holds the file path it seems.cristobal85 commentedon Jan 5, 2021
You can do this with these annotations in yours entities:
parijke commentedon Jan 5, 2021
I have this (but using vich)
parijke commentedon Jan 5, 2021
and my field def:
lauraseidler commentedon Feb 6, 2021
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
Images
entity, and then just associate them.parijke commentedon Feb 7, 2021
@lauraseidler https://www.youtube.com/watch?v=dKX_yREDOmQ&t=619s
Seb33300 commentedon Apr 13, 2024
Same as #5227
I created a PR here: #6258
feature #6258 [ImageField] Support constraint validation (Seb33300)
javiereguiluz commentedon May 21, 2024
Closing as fixed in #6258.