Get raw and relative path of a file uri I have a file with an uri and I want to get its raw and relative path.

Uri: public://videos/Test Video.mp4
Path: /sites/default/files/videos/Test Video.mp4

I found already a way to do this:

$file_uri = $file-&gt;getFileUri();
// public://videos/Test Video.mp4

$absolute_url = file_create_url($file_uri);
// https://www.example.com/sites/default/files/videos/Test%20Video.mp4

$relative_url = file_url_transform_relative($absolute_url);
// /sites/default/files/videos/Test%20Video.mp4

$relative_raw_url = rawurldecode($relative_url);
// /sites/default/files/videos/Test Video.mp4


Is this the Drupal-way? Or is there a better solution for doing this?
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;