How can I get the URL to the public files directory? I can get the path to the public files directory by using Filesystem::realpath:

$path = $filesystem-&gt;realpath('public://');


But how can I get the URL of public://?
$my_path = file_create_url("public://"); 


Will definately work, however it's not coming from a service. Let me investigate more on this!

Okey I found it! This is how file_create_url works:

And this is the corresponding line specific to "public://" resolving (if you are sure you are trying to resolve a "public://..." uri): 

  if ($wrapper = \Drupal::service('stream_wrapper_manager')-&gt;getViaUri($uri)) {
  return $wrapper-&gt;getExternalUrl();
}


Which means you will have to use StreamWrapperManager service, and after calling the getViaUri, you will able to get the external url. So this is service based solution!