Skip to content

[5.5] Support custom URLs for AWS storage #22037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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