Laravel s3 Storage 怎么生成一个指定域名的下载连接?
如$url = Storage::disk('s3')->getTemporaryUrl('a.txt','+1 hours')
使用的是内网endpoint(https://s3-internal.amazonaws.com
)生成的是配置中的endpoint的url如https://s3-internal.amazonaws.com/a.txt?query
.
有没有什么方法可以生成指定域名的url(如自有cdnhttps://file-cdn.domain.com
)
// function temporaryUrl
public function temporaryUrl($path, $expiration, array $options = [])
{
$adapter = $this->driver->getAdapter();
if ($adapter instanceof CachedAdapter) {
$adapter = $adapter->getAdapter();
}
if (method_exists($adapter, 'getTemporaryUrl')) {
return $adapter->getTemporaryUrl($path, $expiration, $options);
} elseif ($adapter instanceof AwsS3Adapter) {
return $this->getAwsTemporaryUrl($adapter, $path, $expiration, $options);
} else {
throw new RuntimeException('This driver does not support creating temporary URLs.');
}
}
// function getAwsTemporaryUrl
public function getAwsTemporaryUrl($adapter, $path, $expiration, $options)\
{
$client = $adapter->getClient();
$command = $client->getCommand('GetObject', array_merge([
'Bucket' => $adapter->getBucket(),
'Key' => $adapter->getPathPrefix().$path,
], $options));
return (string) $client->createPresignedRequest(
$command, $expiration
)->getUri();
}
s3 配置域名解析
字符串替换??