From 70b186f8dd214a6cffebc267b655f37bb89b2634 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Sun, 9 Jun 2019 13:36:30 +0200 Subject: [PATCH 1/3] 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); } /** From 7a1846773406cca1e2e304926269842f5c903af0 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Sun, 9 Jun 2019 13:37:31 +0200 Subject: [PATCH 2/3] stream opening --- StorageBundle/Storage.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/StorageBundle/Storage.php b/StorageBundle/Storage.php index 9a6518e..ec18bcb 100644 --- a/StorageBundle/Storage.php +++ b/StorageBundle/Storage.php @@ -99,12 +99,17 @@ class Storage return $storage->retrieve("$prefix{$entity->{"get".$camel}()}", $local_path); } - public function stream($entity, $attribute, $target_stream) + public function stream($entity, $attribute, $target_stream = null) { $annotation = $this->getStorageAnnotation($entity, $attribute); $storage = $this->get($annotation->name); $prefix = is_null($annotation->prefix) || empty($annotation->prefix) ? '' : trim($annotation->prefix, '/').'/'; $camel = ucfirst(Container::camelize($attribute)); + + if (is_null($target_stream)) { + return $storage->getStream("$prefix{$entity->{"get".$camel}()}"); + } + return $storage->stream("$prefix{$entity->{"get".$camel}()}", $target_stream); } From 9c78c90d76159423315ed46a5663c9bae2c937a1 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Thu, 13 Jun 2019 19:01:39 +0200 Subject: [PATCH 3/3] Fix memory allocation --- StorageBundle/Adaptors/S3Storage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StorageBundle/Adaptors/S3Storage.php b/StorageBundle/Adaptors/S3Storage.php index dba8969..b514b64 100644 --- a/StorageBundle/Adaptors/S3Storage.php +++ b/StorageBundle/Adaptors/S3Storage.php @@ -104,7 +104,8 @@ class S3Storage implements StorageAdaptor 'Bucket' => $this->bucket, 'Path' => $this->getPrefix().$target_path, 'Key' => $this->getPrefix().$target_path, - 'Body' => file_get_contents($source_path), + 'SourceFile' => $source_path, // Fix memory allocation + //'Body' => file_get_contents($source_path), 'ACL' => $permissions ]); }