Streaming download from Swift external storage
Speeds up downloads as they no longer need to buffer completely on the ownCloud server before being sent to the client.
This commit is contained in:
parent
d4a4270adb
commit
cb9a4d4cdc
1 changed files with 10 additions and 17 deletions
|
@ -314,27 +314,20 @@ class Swift extends \OC\Files\Storage\Common {
|
|||
switch ($mode) {
|
||||
case 'r':
|
||||
case 'rb':
|
||||
$tmpFile = \OCP\Files::tmpFile();
|
||||
self::$tmpFiles[$tmpFile] = $path;
|
||||
try {
|
||||
$object = $this->getContainer()->getObject($path);
|
||||
} catch (ClientErrorResponseException $e) {
|
||||
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
} catch (Exception\ObjectNotFoundException $e) {
|
||||
$c = $this->getContainer();
|
||||
$streamFactory = new \Guzzle\Stream\PhpStreamRequestFactory();
|
||||
$streamInterface = $streamFactory->fromRequest(
|
||||
$c->getClient()
|
||||
->get($c->getUrl($path)));
|
||||
$streamInterface->rewind();
|
||||
$stream = $streamInterface->getStream();
|
||||
stream_context_set_option($stream, 'swift','content', $streamInterface);
|
||||
return $stream;
|
||||
} catch (\Guzzle\Http\Exception\BadResponseException $e) {
|
||||
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$objectContent = $object->getContent();
|
||||
$objectContent->rewind();
|
||||
$stream = $objectContent->getStream();
|
||||
file_put_contents($tmpFile, $stream);
|
||||
} catch (Exceptions\IOError $e) {
|
||||
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
return fopen($tmpFile, 'r');
|
||||
case 'w':
|
||||
case 'wb':
|
||||
case 'a':
|
||||
|
|
Loading…
Reference in a new issue