title: Symfony multiple Files total max size constraint
body: <h1>The task</h1>
  <p>The situation is quite typical: I want to allow user to upload multiple files in one form, but total size of all files should not exceed 50 MB.</p>
  <h1>The code</h1>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace Acme\SiteBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\FileType;
  use Symfony\Component\Form\FormBuilderInterface;
  
  class UploadFilesType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('attachedFiles', FileType::class, [
                  'multiple' =&gt; true,
                  'attr' =&gt; [
                      'accept' =&gt; '*/*',
                      'multiple' =&gt; 'multiple',
                  ],
              ])
              -&gt;setMethod('POST');
      }
  
      public function getBlockPrefix()
      {
          return 'uploadFilesForm';
      }
  }
  </code></pre>
  <p>And the corresponding Form Data class.</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace Acme\SiteBundle\Form;
  
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Validator\Constraints as Assert;
  
  class UploadFilesDataType
  {
  
      /**
       * @Assert\All({
       *      @Assert\File(maxSize=&quot;50M&quot;, maxSizeMessage=&quot;File size limit exceeds 50 MB&quot;)
       * })
       */
      private $attachedFiles;
  
      /**
       * @return UploadedFile[]
       */
      public function getAttachedFiles()
      {
          return $this-&gt;attachedFiles;
      }
  
      /**
       * @param UploadedFile[] $attachedFiles
       */
      public function setAttachedFiles($attachedFiles)
      {
          $this-&gt;attachedFiles = $attachedFiles;
      }
  
      /**
       * @param UploadedFile $attachedFile
       */
      public function addAttachedFile($attachedFile)
      {
          $this-&gt;attachedFiles[] = $attachedFile;
      }
  }
  </code></pre>
  <p>Constraints are defined through FormData class' annotations, but could be obviously rewritten to be included in the Form class <code>buildForm()</code> method.</p>
  <h1>The problem</h1>
  <p>The <code>File</code> constraint, which contains <code>maxSize</code> facet can be applied directly to single uploaded file field, but when it goes to multiple uploaded files, then one has to use the <code>All</code> constraint.
  However, with the <code>All</code> constraint one can only define constraint per each element in collection of files (e.g. size of individual uploaded file).</p>
  <p>How can one verify total files size? Is there some combination of existing constraints provided by Symfony? Should one resort to writing her own field validation callback?</p>