public function StreamWrapper::getExternalUrl in AmazonS3 7.2
File
- src/StreamWrapper.php, line 209
- Drupal stream wrapper implementation for Amazon S3
Class
- StreamWrapper
- @file
Drupal stream wrapper implementation for Amazon S3
Namespace
Drupal\amazons3
Code
public function getExternalUrl() {
if (!isset($this->uri)) {
throw new \LogicException('A URI must be set before calling getExternalUrl().');
}
$path_segments = $this->uri
->getPathSegments();
$args = array();
if (!empty($path_segments) && $path_segments[0] === 'styles' && !file_exists((string) $this->uri)) {
return $this
->url($this::stylesCallback . '/' . $this->uri
->getBucket() . $this->uri
->getPath(), array(
'absolute' => TRUE,
));
}
$expiry = NULL;
if ($this
->forceDownload()) {
$args['ResponseContentDisposition'] = $this
->getContentDispositionAttachment();
$expiry = time() + 60 * 60 * 24;
}
$path = $this
->getLocalPath();
if ($this
->useTorrent()) {
$path .= '?torrent';
}
if ($presigned = $this
->usePresigned()) {
$expiry = time() + $presigned
->getTimeout();
}
if ($expiry && $this->config
->isCloudFront()) {
$url = $this
->getCloudFrontUrl($path, $expiry);
}
else {
$args['Scheme'] = $this->config
->getDomainScheme();
$url = $this
->getS3Url($path, $expiry, $args);
}
return (string) $url;
}