diff options
author | Tim Dettrick <t.dettrick@uq.edu.au> | 2015-05-28 18:18:06 +1000 |
---|---|---|
committer | Daniel Tosello <tosello.daniel@gmail.com> | 2015-12-10 15:55:45 +1100 |
commit | cb9a4d4cdcb0bf53121c39d2c918c16a027f69bd (patch) | |
tree | d7a5bdc878b9e1b9568c0a5f2800b8c335967c76 | |
parent | d4a4270adb7dbf4f8a7734106712e920dde72de3 (diff) | |
download | nextcloud-server-cb9a4d4cdcb0bf53121c39d2c918c16a027f69bd.tar.gz nextcloud-server-cb9a4d4cdcb0bf53121c39d2c918c16a027f69bd.zip |
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.
-rw-r--r-- | apps/files_external/lib/swift.php | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index a64a02a4ed9..8311ad202ad 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -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) { - \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) { + $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; } - return fopen($tmpFile, 'r'); case 'w': case 'wb': case 'a': |