Get image file values in $form_state in media entity form I am trying to get the values from an uploaded image inside a media entity during form submit.
Where my approach doesn't work:

When first uploading an image in the media_image_add_form form.
When editing an existing media entity and removing, then uploading a new image and trying to save.

My validation only works when editing and submitting an existing media entity (without changing the uploaded image file).
Here is my entire code for brevity, though it may be long, MYMODULE.module:
/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

  if ($form_id == 'media_image_add_form' || $form_id == 'media_image_edit_form') {

    if ($form_state-&gt;getFormObject()-&gt;getEntity()-&gt;get(&quot;field_media_image&quot;)-&gt;entity) {

      $form['#validate'][] = '_MYMODULE_validate';
    }
  }
}

/**
 * Validates submission values in the FORM_ID() form.
 */
function _MYMODULE_validate(array &amp;$form, FormStateInterface $form_state) {

  // $imageEntity = File::load($form_state-&gt;getValues()['field_media_image'][0]['fids'][0]); // Tried File::load here as well.
  $imageField = $form_state-&gt;getFormObject()-&gt;getEntity()-&gt;get(&quot;field_media_image&quot;);
  $imageEntity = $imageField-&gt;entity;
  $imageFileSize = $imageEntity-&gt;getSize();
  $imageFileMime = $imageEntity-&gt;getMimeType();
  $imageFileName = $imageEntity-&gt;getFilename();
  $isIssue = FALSE;
  $showConditionalMessage = FALSE;
  $ciuMessage = &quot;&quot;;
  $ignoreWarnings = $form_state-&gt;getValues()['field_ignore_warnings']['value']; // Field set on media image entity type.

  // Conditional issue.
  if ($ignoreWarnings === 0 &amp;&amp; $imageFileMime === &quot;image/jpeg&quot; &amp;&amp; $imageFileSize / 1000 &gt; 150) {
    $isIssue = TRUE;
    $showConditionalMessage = TRUE;
    $ciuMessage .= &quot;&lt;p&gt;Conditional: This JPG file size is larger than 150kb, have you optimized this JPG image?&lt;/p&gt;&quot;;
  }

  // Conditional issue.
  if ($ignoreWarnings === 0 &amp;&amp; $imageFileMime === &quot;image/png&quot; &amp;&amp; $imageFileSize / 1000 &gt; 200) {
    $isIssue = TRUE;
    $showConditionalMessage = TRUE;
    $ciuMessage .= &quot;&lt;p&gt;Conditional: This PNG file size is larger than 200kb, have you optimized this PNG image?&lt;/p&gt;&quot;;
  }

  // Non-conditional issue.
  if (strpos($imageFileName, ' ') !== false) {
    $isIssue = TRUE;
    $ciuMessage .= &quot;&lt;p&gt;Filenames cannot contain spaces.&lt;/p&gt;&quot;;
  }

  // Non-conditional issue.
  if (strtolower($imageFileName) !== $imageFileName) {
    $isIssue = TRUE;
    $ciuMessage .= &quot;&lt;p&gt;Filenames need to be in all lowercase.&lt;/p&gt;&quot;;
  }

  if ($isIssue) {
    if ($showConditionalMessage) {
      $ciuMessage .= '&lt;small&gt;To ignore conditional errors, check the &quot;Ignore conditional errors&quot; checkbox below.&lt;/small&gt;';
    }
    $form_state-&gt;setErrorByName('title', new FormattableMarkup($ciuMessage, []));
  }
}

One caveat for using hook_form_alter() is that some of the errors are conditional, and I would like to provide a field on the media entity type to allow ignoring some of the errors.
How can I get the uploaded file/values in $form_state when adding an image to a new media entity, or adding a new image to an existing media entity?
Normally you use a ConstraintValidator for validating entities. In this case core invokes a hook so that you can add your own error messages to the existing file validation process:
function hook_file_validate(Drupal\file\FileInterface $file) {
  $errors = [];

  if (!$file-&gt;getFilename()) {
    $errors[] = t(&quot;The file's name is empty. Please give a name to the file.&quot;);
  }
  if (strlen($file-&gt;getFilename()) &gt; 255) {
    $errors[] = t(&quot;The file's name exceeds the 255 characters limit. Please rename the file and try again.&quot;);
  }

  return $errors;
}

About the caveat for using form alter. You can add custom #upload_validatorsto the image widget. Add settings if necessary:
$element['#upload_validators']['my_custom_file_validator'] = [$my_setting];