I'm using assert in my entity:
/**
* @ORM\Column(type="text", nullable=true)
*/
private $picture;
/**
* @Vich\UploadableField(mapping="user.picture", fileNameProperty="picture")
*
* @Assert\Image(maxSize="1M")
*/
private $pictureFile;
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getPictureFile()
{
return $this->pictureFile;
}
public function setPictureFile($pictureFile): void
{
$this->pictureFile = $pictureFile;
if(null !== $pictureFile) {
$this->setUpdatedAtValue();
}
}
and my controller is:
$form = $this->createForm(UserType::class, $this->getUser());
$form->handleRequest($request);
if($form->isSubmitted()){
if($form->isValid()){
$this->getUser()->setIsRegister(true);
$em = $this->getDoctrine()->getManager();
$em->flush();
return $this->redirectToRoute('app_profile_edit');
}
}
my form field:
->add('pictureFile', VichImageType::class, ['required' => false, 'download_label' => false, 'image_uri' => false])
but the assert not worked and file woll uploaded without any errors.
Validation is not part of this bundle
Could you please say to me how to validate my image mime type or size and etc. ?
You can find all informations you need on documentation
worked when I add it to the form:
->add('pictureFile', VichImageType::class, ['required' => false, 'download_label' => false, 'image_uri' => false, 'constraints' => [new Image(['maxSize' => '2M'])]])
Most helpful comment
worked when I add it to the form:
->add('pictureFile', VichImageType::class, ['required' => false, 'download_label' => false, 'image_uri' => false, 'constraints' => [new Image(['maxSize' => '2M'])]])