KnpLabs / KnpGaufretteBundle

Easily use Gaufrette in your Symfony projects.
http://knplabs.com
MIT License
716 stars 157 forks source link

Entity validation #170

Open LeighBicknell opened 6 years ago

LeighBicknell commented 6 years ago

Good afternoon!

Unless I'm doing something wrong, it seems entity file validation doesn't appear to work out of the box?

     * @Assert\Image(
     *      minWidth = 200,
     *      minWidthMessage = "The image must be at least 200x200px",
     *      maxWidth = 20000,
     *      maxWidthMessage = "The image must be below 20,000x20,000px",
     *      minHeight = 200,
     *      minHeightMessage = "The image must be at least 200x200px",
     *      maxHeight = 20000,
     *      maxHeightMessage = "The image must be below 20,000x20,000px",
     *      sizeNotDetectedMessage = "Image size couldn't be detected",
     *      detectCorrupted = true,
     *      corruptedMessage = "The image is corrupt!"
     * )

The form fails validation with 'File not found' which makes sense as the path to the file stored in the entities property is simply '/{random}' by default.

Is there a way to make entity validation work?

KoriSeng commented 6 years ago

need to some how convert the path from gaufrette to a symfony file object, but this is more upload portion?

it should work out of the box when you use the symfony form to do upload/verification after which getting the data from the form to right to the fs, however if you are fetching path from database and do the verification after fetching, you need to convert that path into file object as mentioned above.

https://symfony.com/doc/current/reference/forms/types/file.html http://api.symfony.com/4.0/Symfony/Component/HttpFoundation/File/File.html