You are here

public function PrivateStream::getExternalUrl in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/StreamWrapper/PrivateStream.php \Drupal\Core\StreamWrapper\PrivateStream::getExternalUrl()
  2. 10 core/lib/Drupal/Core/StreamWrapper/PrivateStream.php \Drupal\Core\StreamWrapper\PrivateStream::getExternalUrl()

Returns a web accessible URL for the resource.

This function should return a URL that can be embedded in a web page and accessed from a browser. For example, the external URL of "youtube://xIpLd0WQKCY" might be "http://www.youtube.com/watch?v=xIpLd0WQKCY".

Return value

string Returns a string containing a web accessible URL for the resource.

Overrides StreamWrapperInterface::getExternalUrl

File

core/lib/Drupal/Core/StreamWrapper/PrivateStream.php, line 47

Class

PrivateStream
Drupal private (private://) stream wrapper class.

Namespace

Drupal\Core\StreamWrapper

Code

public function getExternalUrl() {
  $path = str_replace('\\', '/', $this
    ->getTarget());
  return Url::fromRoute('system.private_file_download', [
    'filepath' => $path,
  ], [
    'absolute' => TRUE,
    'path_processing' => FALSE,
  ])
    ->toString();
}