Merge branch 'master' of ssh://git.bluesquare.io/bluesquare-packages/symfony-storage

This commit is contained in:
Maxime Renou 2019-07-11 16:55:58 +02:00
commit 8854ca314d
2 changed files with 23 additions and 9 deletions

View File

@ -111,7 +111,8 @@ class S3Storage implements StorageAdaptor
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
'Path' => $this->getPrefix().$target_path, 'Path' => $this->getPrefix().$target_path,
'Key' => $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 '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 * Permet de stream un fichier stocké dans S3
* @param $distant_path * @param $distant_path
* @param $target_stream * @param $target_stream
*/ */
public function stream ($distant_path, $target_stream) public function stream ($distant_path, $target_stream)
{ {
$aws_stream = $this->client->getObject([ stream_copy_to_stream($this->getStream($distant_path), $target_stream);
'Bucket' => $this->bucket,
'Key' => $this->getPrefix().$distant_path,
'Path' => $this->getPrefix().$distant_path,
])->get('Body')->detach();
stream_copy_to_stream($aws_stream, $target_stream);
} }
/** /**

View File

@ -99,12 +99,17 @@ class Storage
return $storage->retrieve("$prefix{$entity->{"get".$camel}()}", $local_path); 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); $annotation = $this->getStorageAnnotation($entity, $attribute);
$storage = $this->get($annotation->name); $storage = $this->get($annotation->name);
$prefix = is_null($annotation->prefix) || empty($annotation->prefix) ? '' : trim($annotation->prefix, '/').'/'; $prefix = is_null($annotation->prefix) || empty($annotation->prefix) ? '' : trim($annotation->prefix, '/').'/';
$camel = ucfirst(Container::camelize($attribute)); $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); return $storage->stream("$prefix{$entity->{"get".$camel}()}", $target_stream);
} }