Stream downloads from Swift object stores without downloading it first

This commit is contained in:
Robin Appelman 2014-08-22 14:11:21 +02:00
parent 9c980954f4
commit 191a82e768
1 changed files with 4 additions and 5 deletions

View File

@ -120,12 +120,11 @@ class Swift implements IObjectStore {
$objectContent = $object->getContent(); $objectContent = $object->getContent();
$objectContent->rewind(); $objectContent->rewind();
// directly returning the object stream does not work because the GC seems to collect it, so we need a copy $stream = $objectContent->getStream();
$tmpStream = fopen('php://temp', 'r+'); // save the object content in the context of the stream to prevent it being gc'd until the stream is closed
stream_copy_to_stream($objectContent->getStream(), $tmpStream); stream_context_set_option($stream, 'swift','content', $objectContent);
rewind($tmpStream);
return $tmpStream; return $stream;
} }
/** /**