phpsymfonyannotationssymfony4

Annotation error while trying to upload image using symfony 4.4


enter image description hereI am using Symfony 4.4 and trying to upload an image. But while creating schemas I am getting an Annotation error.

[Semantical Error]
The annotation "@Symfony\Component\Validator\Constraints\Image\Image" in property App\Entity\Student::$photo was never imported.
Did you maybe forget to add a "use" statement for this annotation?

Attaching the code snippets below, please say what is the mistake I made.

use Symfony\Component\Validator\Constraints as Assert;

/** 
  * @Assert\NotBlank(message="Please, upload the photo.") 
  * @Assert\File(mimeTypes={ "image/png", "image/jpeg" }) 
  */
private $photo;

Solution

  • It looks like you forgot to add use Symfony\Component\Validator\Constraints as Assert; to the top of the file.

    According to the error message and the documentation for NoBlank, that line should fix your issue.