UploadField `getValidator` not working

Silverstripe Version: 5.2

Question:
Hi there, we’re using the UploadField for both images and files and want to add validation for allowed file types.

I’m sure before I could do the following and it would :

private static array $has_one = [
    'Video' => File::class, // No validation
    // Video' => Image::class // Has validation
];

$fldVideo = UploadField::create('Video', 'Video');
$fldVideoValidator = $fldVideo->getValidator();
$fldVideoValidator->setAllowedExtensions(['jpg', 'jpeg', 'png']);
$fldVideoValidator->setAllowedMaxFileSize('300kb');
$fldVideo->setFolderName('Uploads/large');

It seems to validate if the $has_one uses an Image::class, but doesn’t validate if it’s a File::class. Is this intended?

Thanks,
Jack

You’re calling getValidator() on the validator. There is no getValidator() method on the Upload_Validator class.

Whoops sorry! I refactored my code in the post to make it clearer but in effect made it worse :man_facepalming:

In any case, it doesn’t seem like the validator is working on a File::class (when I use it correctly :grimacing:).

Are there any known caveats using the validator on the File::class as it does work fine with the Image::class?

To the best of my knowledge, no - upload validation should be performed for File relations just like with Image relations.