diff --git a/StorageBundle/Adaptors/S3Storage.php b/StorageBundle/Adaptors/S3Storage.php index 4ad420c..8001821 100644 --- a/StorageBundle/Adaptors/S3Storage.php +++ b/StorageBundle/Adaptors/S3Storage.php @@ -111,7 +111,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 ]); } @@ -136,19 +137,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); } /** 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); }