imageService->resolveFromUrlId($path); $imagePath = $this->pathProvider->resolvePath('storage' . $image->uploadPath . '/' . $filename); #debug($imagePath); // Prüfen ob Datei existiert if (!file_exists($imagePath)) { die('oh'); return $this->notFound(); } // Lese Datei und sende sie zurück $content = file_get_contents($imagePath); $mimeType = $this->getMimeTypeFromFormat($image->mimeType); $headers = new Headers([ 'Content-Type' => $mimeType, 'Content-Length' => filesize($imagePath), 'Cache-Control' => 'public, max-age=31536000', // 1 Jahr cachen 'ETag' => '"' . md5_file($imagePath) . '"', ]); return new FileResult($imagePath); return new HttpResponse( Status::OK, $headers, $content ); } private function constructImagePath(Image $image, string $variant, string $format): string { return $this->pathProvider->resolvePath('storage' . $image->uploadPath . '/' . $variant . '.' . $format); } private function getMimeTypeFromFormat(string $format): string { return match ($format) { 'jpg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', 'avif' => 'image/avif', default => 'application/octet-stream' }; } private function notFound(): HttpResponse { return new HttpResponse( Status::NOT_FOUND, new Headers(['Content-Type' => 'text/plain']), 'Bild nicht gefunden' ); } }