public function RemoteImageStyleDownloadController::deliver in Remote Stream Wrapper 8
Generates a derivative, given a style and image path.
After generating an image, transfer it to the requesting agent.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
string $scheme: The file scheme, defaults to 'private'.
\Drupal\image\ImageStyleInterface $image_style: The image style to deliver.
Return value
\Symfony\Component\HttpFoundation\BinaryFileResponse|\Symfony\Component\HttpFoundation\Response The transferred file as response or some error response.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown when the file request is invalid.
\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException Thrown when the user does not have access to the file.
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException Thrown when the file is still being generated.
Overrides ImageStyleDownloadController::deliver
File
- src/
Controller/ RemoteImageStyleDownloadController.php, line 35
Class
- RemoteImageStyleDownloadController
- Defines a controller to serve image styles.
Namespace
Drupal\remote_stream_wrapper\ControllerCode
public function deliver(Request $request, $scheme, ImageStyleInterface $image_style) {
// Only allow the remote files that exist in {file_managed} to have image
// style derivatives generated. Otherwise this could open up the site to
// allowing any remote file to be processed.
$target = $request->query
->get('file');
$image_uri = $scheme . '://' . $target;
if (!$this->fileStorage
->loadByProperties([
'uri' => $image_uri,
])) {
throw new AccessDeniedHttpException();
}
return parent::deliver($request, $scheme, $image_style);
}