Skip to content

Commit

Permalink
Support custom URLs for AWS storage
Browse files Browse the repository at this point in the history
  • Loading branch information
nesk committed Nov 9, 2017
1 parent 8be87d4 commit 7a32247
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ public function url($path)
*/
protected function getAwsUrl($adapter, $path)
{
$config = $this->driver->getConfig();

// If an explicit base URL has been set on the disk configuration then we will use
// it as the base URL instead of the default path. This allows the developer to
// have full control over the base path for this filesystem's generated URLs.
if (! is_null($url = $config->get('url'))) {
return $this->concatPathToUrl($url, $path);
}

return $adapter->getClient()->getObjectUrl(
$adapter->getBucket(), $adapter->getPathPrefix().$path
);
Expand Down Expand Up @@ -381,7 +390,7 @@ protected function getLocalUrl($path)
// it as the base URL instead of the default path. This allows the developer to
// have full control over the base path for this filesystem's generated URLs.
if ($config->has('url')) {
return rtrim($config->get('url'), '/').'/'.ltrim($path, '/');
return $this->concatPathToUrl($config->get('url'), $path);
}

$path = '/storage/'.$path;
Expand Down Expand Up @@ -460,6 +469,18 @@ public function getRackspaceTemporaryUrl($adapter, $path, $expiration, $options)
);
}

/**
* Concatenate a path to a URL.
*
* @param string $url
* @param string $path
* @return string
*/
protected function concatPathToUrl($url, $path)
{
return rtrim($url, '/').'/'.ltrim($path, '/');
}

/**
* Get an array of all files in a directory.
*
Expand Down

0 comments on commit 7a32247

Please sign in to comment.