Skip to content
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

[8.x] Use user provided url in AwsTemporaryUrl method #36480

Merged
merged 1 commit into from
Mar 7, 2021
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
26 changes: 25 additions & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use League\Flysystem\Sftp\SftpAdapter as Sftp;
use PHPUnit\Framework\Assert as PHPUnit;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;

Expand Down Expand Up @@ -593,9 +594,18 @@ public function getAwsTemporaryUrl($adapter, $path, $expiration, $options)
'Key' => $adapter->getPathPrefix().$path,
], $options));

return (string) $client->createPresignedRequest(
$uri = $client->createPresignedRequest(
$command, $expiration
)->getUri();

// 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 = $this->driver->getConfig()->get('url'))) {
$uri = $this->replaceBaseUrl($uri, $url);
}

return (string) $uri;
}

/**
Expand All @@ -610,6 +620,20 @@ protected function concatPathToUrl($url, $path)
return rtrim($url, '/').'/'.ltrim($path, '/');
}

/**
* Replace base parts of UriInterface by values from URL.
*
* @param UriInterface $uri
* @param string $url
* @return UriInterface
jnoordsij marked this conversation as resolved.
Show resolved Hide resolved
*/
protected function replaceBaseUrl($uri, $url)
{
$parsed_url = parse_url($url);

return $uri->withScheme($parsed_url['scheme'])->withHost($parsed_url['host']);
}

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