Load a file entity by URI Is there a way to load a file by URI in Drupal 9 and/or Drupal 8?
In Drupal 7 it is possible using the following code.
$uri = 'public://file.xyz';

// Take a look at: file.inc::file_load_multiple
$files = file_load_multiple(array(), array('uri' =&gt; $uri));
$file = reset($files); // If empty, $file will be false, otherwise will contain the required file

Taken from here https://www.drupal.org/forum/support/module-development-and-code-questions/2012-06-06/load-a-file-by-uri#comment-6493610
There is the loadByProperties method in the \Drupal\Core\Entity\EntityStorageInterface that allows to define required condition in searching the file entity by the given file URI:
/** @var \Drupal\file\FileInterface[] $files */
$files = \Drupal::entityTypeManager()
  -&gt;getStorage('file')
  -&gt;loadByProperties(['uri' =&gt; $uri]);
/** @var \Drupal\file\FileInterface|null $file */
$file = reset($files) ?: NULL;