- Issue created by @KlemenDEV
- ๐ณ๐ฟNew Zealand quietone
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies โ
- ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
The event is for altering validation constraints. If you are creating a new one, you probably want to implement your own
ConstraintValidator
plug-in that extends\Drupal\file\Plugin\Validation\Constraint\BaseFileConstraintValidator
. - Status changed to Needs work
4 months ago 2:29pm 1 May 2025 - ๐ธ๐ฎSlovenia KlemenDEV
Looking at this change record - https://www.drupal.org/node/3363700 โ - it recommends replacing hook_file_validate with FileValidationEvent. Is the change record wrong in this case? Because, as explained at https://www.drupal.org/project/clamav/issues/3503176#comment-15967597 ๐ File upload stopped working after updating to 2.1.0 Active , the module adapted the recommended event replacement
- ๐ธ๐ฎSlovenia KlemenDEV
Also, shouldn't this event still provide the correct file size when uploading, as if you check my post, the uploaded file data is not correct when using FileValidationEvent?
- ๐ธ๐ฎSlovenia KlemenDEV
This may also be happening because the images are downsized if too big, and then two different sizes are in question - the true size and the resized one. Related: https://www.drupal.org/project/drupal/issues/3292350#comment-16093652 ๐ file_validate_image_resolution does not update file size after resizing Needs work
- ๐ณ๐ฑNetherlands roderik Amsterdam,NL / Budapest,HU
As just an interested reader, arriving here via the CR ( https://www.drupal.org/node/3363700 โ ) -> ๐ File upload stopped working after updating to 2.1.0 Active :
Looking at this change record - https://www.drupal.org/node/3363700 โ - it recommends replacing hook_file_validate with FileValidationEvent. Is the change record wrong in this case?
Looks to me like the change record isn't wrong, and there may be a bit of terminology mix-up going on here. Maybe you are aware of this already, but then I'm just summarizing for other readers:
1)
The event is specifically for altering the behavior of FileValidator. That is, usually: add extra constraints to the validator.ClamAV does that. And I don't see any indication that ClamAV should be doing anything else.
2)
Re #5: Yes, if the size in the file object passed to FileValidator (and then to the event) is wrong, then that's strange, and that is the part that should be fixed -- at least that's what it seems like to me. The code subscribing to the event (like ClamAV) can't help this.This actually means (seems to me) that the title of this issue is wrong, and FileValidationEvent is fine. As long as it doesn't get a file object with wrong/outdated info.
And the related ๐ FileValidationEvent may not report the correct file size Active (file resizing) feels like a plausible candidate for code that's buggy and should fix the file size in the file object. (I can't judge that without diving into that code.) So this issue can be closed "(works as designed)" (perhaps after ๐ FileValidationEvent may not report the correct file size Active is fixed).
- ๐ซ๐ทFrance o'briat Nantes
I think the core problem is that
FileImageDimensionsConstraintValidator
changes the file size during a validation process, according to https://www.drupal.org/project/drupal/issues/3363745 ๐ Deprecate file_validate_image_resolution() and replace with a service Postponed this validation process should only does checks and returns info/errors.This quick fix is to update the object's file size after resizing it (done again in https://www.drupal.org/project/drupal/issues/3522463 ๐ FileValidationEvent may not report the correct file size Active ), the long way is (IMHO) to redefine the API/events workflow of file Validator.
Should this issue closed and marked as duplicated of https://www.drupal.org/project/drupal/issues/3522463 ๐ FileValidationEvent may not report the correct file size Active ?
- ๐ธ๐ฎSlovenia KlemenDEV
Closing as duplicate of https://www.drupal.org/project/drupal/issues/3522463 ๐ FileValidationEvent may not report the correct file size Active