+ /**
+ * Return download file
+ *
+ * @param Request $request The Request instance
+ * @param string $hash The hash
+ * @param string $path The image path
+ * @return Response The rendered image
+ */
+ public function download(Request $request, string $hash, string $path/*, string $_format*/): Response {
+ //Without matching hash
+ if ($hash !== $this->slugger->hash($path)) {
+ //Throw new exception
+ throw new NotFoundHttpException('Invalid download hash');
+ //Without valid format
+ #} elseif ($_format !== 'jpeg' && $_format !== 'png' && $_format !== 'webp') {
+ # //Throw new exception
+ # throw new NotFoundHttpException('Invalid download format');
+ }
+
+ //Unshort path
+ $path = $this->slugger->unshort($short = $path);
+
+ //Without file
+ if (!is_file($path) || !($mtime = stat($path)['mtime'])) {
+ //Throw new exception
+ throw new NotFoundHttpException('Unable to get thumb file');
+ }
+
+ //Read thumb from cache
+ $response = new BinaryFileResponse($path);
+
+ //Set file name
+ $response->setContentDisposition(HeaderUtils::DISPOSITION_INLINE, basename($path));
+
+ //Set etag
+ //TODO: set etag to file content md5 ? cache it ?
+ $response->setEtag(md5($hash));
+
+ //Set last modified
+ $response->setLastModified(\DateTime::createFromFormat('U', strval($mtime)));
+
+ //Set as public
+ $response->setPublic();
+
+ //Return 304 response if not modified
+ $response->isNotModified($request);
+
+ //Return response
+ return $response;
+ }
+