title: How to use Assert\File and Assert\Image at the same time in Symfony?
body: <p>I'm trying to validate a file upload with 2 conditions:</p>
  <blockquote>
  <ol>
  <li><p>Only allowed to upload image file or PDF file</p>
  </li>
  <li><p>Max width with Image file is 160px and no requirement with PDF file</p>
  </li>
  </ol>
  </blockquote>
  <p>I used &quot;Constraints&quot; of Symfony but when I upload a PDF file, it said that</p>
  <blockquote>
  <p>This file is not a valid image.</p>
  </blockquote>
  <p>Because I used both Assert\Image and Assert\File at the same time, so it will check whether the file is image or not first.</p>
  <p>But <strong>What I want</strong> is that when I upload a file, it will check Assert\File first. If it's an image, then it will check Assert\Image. How can I do?</p>
  <p>Here is my code at Entity:</p>
  <pre><code>   /**
       * @Vich\UploadableField(mapping=&quot;ad&quot;, fileNameProperty=&quot;imageFile&quot;)
       * @var File
       * @Assert\File(
       *     mimeTypes = {&quot;application/pdf&quot;, &quot;application/x-pdf&quot;, &quot;image/png&quot;, &quot;image/jpeg&quot;, &quot;image/svg+xml&quot;},
       *     mimeTypesMessage = &quot;You can only be allowed to upload Image file or PDF file&quot;
       * )
       * @Assert\Image(
       *     maxWidth = 160
       * )
       */
      private $image;
  </code></pre>