fix(fixminio): stream image from minio (#6)
Cadoles/nineskeletor/pipeline/head Something is wrong with the build of this commit Details

fix load image from minio

Co-authored-by: Arnaud Fornerot <afornerot@cadoles.com>
Reviewed-on: #6
This commit is contained in:
afornerot 2022-10-24 13:47:43 +02:00
parent cb766ee2f9
commit 928109fdf5
2 changed files with 26 additions and 2 deletions

View File

@ -73,8 +73,7 @@ class MinioController extends AbstractController
} }
// C'est du contenu dynamique on download depuis minio // C'est du contenu dynamique on download depuis minio
else { else {
$filePath = $this->minio->download($file, $file, true); return new Response($this->minio->image($file, $file));
$content = file_get_contents($filePath);
} }
break; break;
} }

View File

@ -30,6 +30,31 @@ class MinioService
$this->initBucket(); $this->initBucket();
} }
public function image(string $file, string $filename)
{
try {
$result = $this->client->getObject([
'Bucket' => $this->minioBucket,
'Key' => $this->minioRoot.$file,
]);
} catch (S3Exception $e) {
switch ($e->getResponse()->getStatusCode()) {
case 404:
throw new NotFoundHttpException(self::ERR_FILE_NOT_FOUND);
break;
default:
\Sentry\captureException($e);
throw new Exception(self::ERR_UNAVAILABLE);
break;
}
} catch (Exception $e) {
\Sentry\captureException($e);
throw new Exception(self::ERR_UNAVAILABLE);
}
return $result->get('Body');
}
public function download(string $file, string $filename, bool $usecache = true) public function download(string $file, string $filename, bool $usecache = true)
{ {
// On s'assure que le repertoire temporaire de destination existe bien // On s'assure que le repertoire temporaire de destination existe bien