Get raw and relative path of a file uri
I had to do this recently and found this solution using Drupal 9.1.
$file = File::load($fid);

$relative_file_url = $file-&gt;createFileUrl(TRUE);
$absolute_file_url = $file-&gt;createFileUrl(FALSE);

I found the createFileUrl() function in web/core/modules/file/src/Entity/File.php.  Maybe this would be considered &quot;the way?&quot;