From 70b186f8dd214a6cffebc267b655f37bb89b2634 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Sun, 9 Jun 2019 13:36:30 +0200 Subject: [PATCH] stream opening --- StorageBundle/Adaptors/S3Storage.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/StorageBundle/Adaptors/S3Storage.php b/StorageBundle/Adaptors/S3Storage.php index 69f89f4..dba8969 100644 --- a/StorageBundle/Adaptors/S3Storage.php +++ b/StorageBundle/Adaptors/S3Storage.php @@ -129,19 +129,27 @@ class S3Storage implements StorageAdaptor } /** + * Ouvre le stream d'un fichier stocké dans S3 + * @param $distant_path + * @param $target_stream + */ + public function getStream ($distant_path) + { + return $this->client->getObject([ + 'Bucket' => $this->bucket, + 'Key' => $this->getPrefix().$distant_path, + 'Path' => $this->getPrefix().$distant_path, + ])->get('Body')->detach(); + } + + /** * Permet de stream un fichier stocké dans S3 * @param $distant_path * @param $target_stream */ public function stream ($distant_path, $target_stream) { - $aws_stream = $this->client->getObject([ - 'Bucket' => $this->bucket, - 'Key' => $this->getPrefix().$distant_path, - 'Path' => $this->getPrefix().$distant_path, - ])->get('Body')->detach(); - - stream_copy_to_stream($aws_stream, $target_stream); + stream_copy_to_stream($this->getStream($distant_path), $target_stream); } /**