Get web image url from real path As part of some other functionality I am generating an image in temp folder and But unforunately I'm not able get the web url of image.

$path = \Drupal::service('file_system')-&gt;realpath(file_default_scheme() . "://");
$image_path = $path . rand() . '.png';
echo $image_path;


I am getting following as path

C:\wamp\www\www_d8test1_com\sites\default\files30605.png


How can I add slash before image name and get actual weburl of image like below?

http://www.d8test1.com/sites/default/files/30605.png
You can check out the file_create_url() function that creates a URL for your file.

So, based on the code in your question, it would look like:

// Generate or get the image uri.
$image_uri = file_default_scheme() . "://";
// Create the url from the uri.
$image_path = file_create_url($image_uri);