Answers.Body: <p>Currently, no. The only file-based validation Assets fields have right now is the type. If you want to enforce a certain size, you can do that on the template end using <a href="http://buildwithcraft.com/docs/image-transforms" rel="nofollow">image transforms</a>. I would suggest adding some instruction text to your Assets field that provides a minimum suggested size, and note that smaller images will be scaled up and look gross.</p>
  
  <p>That said, if you <em>really</em> want to enforce a minimum width/height, or other properties, you can do so by writing a plugin that provides its own field type, which extends <a href="http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType" rel="nofollow">AssetsFieldType</a> and overrides its <a href="http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType#validate-detail" rel="nofollow">validate()</a> method with your custom validation:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function validate($value)
  {
      // Let AssetsFieldType do its validation first
      $errors = parent::validate($value);
  
      if (!is_array($errors))
      {
          $errors = array();
      }
  
      if (is_array($value) &amp;&amp; !empty($value))
      {
          foreach ($value as $fileId)
          {
              $file = craft()-&gt;assets-&gt;getFileById($fileId);
  
              if ($file)
              {
                  if ($file-&gt;width &lt; 600 || $file-&gt;height &lt; 400)
                  {
                      $errors[] = Craft::t(
                          '{filename} must be at least 600x400px.',
                          array('filename' =&gt; $file-&gt;filename)
                      );
                  }
              }
          }
      }
  
      if ($errors)
      {
          return $errors;
      }
      else
      {
          return true;
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-09T08:57:14.110Z
Answers.Text: I do want to enforce this, the site has public members we won't be able to give training to, and from experience: people don't read instructions - though I've put some there already. Thanks Brandon, this is what I need!
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-09T09:20:51.137Z
Answers.Text: Brandon, could you please repost this as an answer to the earlier question about this topic, as this one here got closed.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-09T10:31:31.037Z
Answers.Text: @carlcs just did.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-08T17:59:27.800Z
Answers.LastActivityDate: 2014-10-08T17:59:27.800Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Craft will let us define what file-type is valid for a given asset field, but there are many times where I'd like to enforce other properties too - e.g., a minimum dimension for valid images uploaded to that field (i.e., dimensions must be larger than 800x600). Is there a way to do that? </p>
  
  <p>Currently I can only see Craft enforcing file-types and file-size limits if they're too large (e.g., 4Mb is too big). I'd like some more options to avoid clients uploading unsuitable files.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-07T09:43:15.497Z
Comments.Text: That's a similar issue though not quite the same, and was not really answered :/
Comments.UserDisplayName: Matt Wilcox
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-07T11:07:40.700Z
Comments.Text: What's the difference? Both, min. and exact dimensions would need some sort of check before uploading. And in my opinion the answer there is rather clear: not possible with default CP. You need a plugin with custom uploader.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-08T08:56:24.180Z
Comments.Text: The difference is I'm asking in general, not just about images - that was one example of a property to enforce for a valid upload file.
Comments.UserDisplayName: Matt Wilcox
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-08T10:11:01.470Z
Comments.Text: Could you be more specific on the properties you want to check besides type, size and dimensions?
Comments.UserDisplayName: carlcs
Tags: <assets>
Title: Can we set properties to establish a valid asset per field?
ThreadText: # Can we set properties to establish a valid asset per field?
  
  (Asked by: username_0 on 2014-10-07)
  
  Craft will let us define what file-type is valid for a given asset field, but there are many times where I'd like to enforce other properties too - e.g., a minimum dimension for valid images uploaded to that field (i.e., dimensions must be larger than 800x600). Is there a way to do that?
  
  Currently I can only see Craft enforcing file-types and file-size limits if they're too large (e.g., 4Mb is too big). I'd like some more options to avoid clients uploading unsuitable files.
  
  **Tags:** assets
  
  > **Comments:**
  > **username_0**: That's a similar issue though not quite the same, and was not really answered :/  
  > **username_1**: What's the difference? Both, min. and exact dimensions would need some sort of check before uploading. And in my opinion the answer there is rather clear: not possible with default CP. You need a plugin with custom uploader.  
  > **username_0**: The difference is I'm asking in general, not just about images - that was one example of a property to enforce for a valid upload file.  
  > **username_1**: Could you be more specific on the properties you want to check besides type, size and dimensions?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-10-08. Score: 4 | Accepted answer
  
  Currently, no. The only file-based validation Assets fields have right now is the type. If you want to enforce a certain size, you can do that on the template end using [image transforms](http://buildwithcraft.com/docs/image-transforms). I would suggest adding some instruction text to your Assets field that provides a minimum suggested size, and note that smaller images will be scaled up and look gross.
  
  That said, if you *really* want to enforce a minimum width/height, or other properties, you can do so by writing a plugin that provides its own field type, which extends [AssetsFieldType](http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType) and overrides its [validate()](http://buildwithcraft.com/classreference/fieldtypes/AssetsFieldType#validate-detail) method with your custom validation:
  
  ```php
  public function validate($value)
  {
      // Let AssetsFieldType do its validation first
      $errors = parent::validate($value);
  
      if (!is_array($errors))
      {
          $errors = array();
      }
  
      if (is_array($value) && !empty($value))
      {
          foreach ($value as $fileId)
          {
              $file = craft()->assets->getFileById($fileId);
  
              if ($file)
              {
                  if ($file->width < 600 || $file->height < 400)
                  {
                      $errors[] = Craft::t(
                          '{filename} must be at least 600x400px.',
                          array('filename' => $file->filename)
                      );
                  }
              }
          }
      }
  
      if ($errors)
      {
          return $errors;
      }
      else
      {
          return true;
      }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: I do want to enforce this, the site has public members we won't be able to give training to, and from experience: people don't read instructions - though I've put some there already. Thanks username_2, this is what I need!  
  > **username_1**: username_2, could you please repost this as an answer to the earlier question about this topic, as this one here got closed.  
  > **username_2**: @username_1 just did.  
  
  ---
  
  