Merge branch 'master' of ssh://git.bluesquare.io/bluesquare-packages/symfony-storage
This commit is contained in:
commit
8854ca314d
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue