Hello,
Thanks for the bundle, the upload works wonderfully. However, I'm trying to put a constraint on the uploadedFile for instance :
use Symfony\Component\Validator\Constraints as Assert;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Assert\Image{
* maxWidth=400,
* maxHeight=400
* }
* @Vich\UploadableField(mapping="user_avatar", fileNameProperty="avatarName")
*
* @var File
*/
private $avatarFile;
But the constraint is not working and i can upload image of whatever dimensions, how should I fix that ? Thanks.
How do use it in the your form? Your exact snippet worked on my tests.
Hi,
I use it as the following :
if ($editForm->handleRequest($request)->isValid()) {
//$this->getDoctrine()->getManager()->flush();
$userManager = $this->get('fos_user.user_manager');
$userManager->updateUser($user);
return $this->redirect($this->generateUrl('users'));
}
I use FOSUserBundle to handle users and such, so if you said it's working it's something with fosuser validation :(
Thanks
If you are using a CollectionType for your uploads on your form you'll need to use the Valid constraint on the property on the parent entity.
You have to use parenthesis instead of brackets :
* @Assert\Image(
* maxWidth=400,
* maxHeight=400
* )
Most helpful comment
If you are using a CollectionType for your uploads on your form you'll need to use the Valid constraint on the property on the parent entity.