protected function TextimageDownloadController::returnBinary in Textimage 8.4
Same name and namespace in other branches
- 8.3 src/Controller/TextimageDownloadController.php \Drupal\textimage\Controller\TextimageDownloadController::returnBinary()
Returns the image file at URI.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
string $uri: The URI of the file to be returned.
Return value
\Symfony\Component\HttpFoundation\BinaryFileResponse|\Symfony\Component\HttpFoundation\Response The transferred file as response or some error response.
2 calls to TextimageDownloadController::returnBinary()
- TextimageDownloadController::deferredDelivery in src/
Controller/ TextimageDownloadController.php - Deliver a Textimage from a deferred request.
- TextimageDownloadController::urlDeliver in src/
Controller/ TextimageDownloadController.php - Deliver directly a Textimage from the URL request.
File
- src/
Controller/ TextimageDownloadController.php, line 213
Class
- TextimageDownloadController
- Defines a controller to serve image styles.
Namespace
Drupal\textimage\ControllerCode
protected function returnBinary(Request $request, $uri) {
// Don't try to send file if it is missing.
if (!file_exists($uri)) {
$this->logger
->notice("Textimage image at '%source_image_path' not found.", [
'%source_image_path' => $uri,
]);
return new Response($this
->t('Error downloading a textimage.'), 404);
}
if (($scheme = $this->streamWrapperManager
->getScheme($uri)) == 'private') {
// If using the private scheme, defer control to FileDownloadController.
$request->query
->set('file', $this->streamWrapperManager
->getTarget($uri));
return parent::download($request, $scheme);
}
else {
// Get the image and transfer to client.
$image = $this->imageFactory
->get($uri);
$uri = $image
->getSource();
$headers = [
'Content-Type' => $image
->getMimeType(),
'Content-Length' => $image
->getFileSize(),
];
return new BinaryFileResponse($uri, 200, $headers);
}
}