summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-22 17:27:41 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-22 17:27:41 +0100
commit0a4142d5dff8427faff4a8ba8c0d6ac5abfae780 (patch)
treee86a9a1be7fc0ec36d3b12c2f91425c4a6671f06
parent99e9c81c8b3180d973a256697f0f20ce3d76569a (diff)
parent8783eb99f7db7c8d08f2b33223a9a547438c021a (diff)
downloadnextcloud-server-0a4142d5dff8427faff4a8ba8c0d6ac5abfae780.tar.gz
nextcloud-server-0a4142d5dff8427faff4a8ba8c0d6ac5abfae780.zip
Merge pull request #19002 from UoM-ResPlat-DevOps/swift-streaming-download
Streaming download from Swift in files_external
-rw-r--r--apps/files_external/lib/swift.php29
1 files changed, 13 insertions, 16 deletions
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 8f58a50b294..1f092240b4d 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -323,27 +323,24 @@ 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);
+ $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);
+ if(!strrpos($streamInterface
+ ->getMetaData('wrapper_data')[0], '404 Not Found')) {
+ return $stream;
+ }
return false;
- }
- try {
- $objectContent = $object->getContent();
- $objectContent->rewind();
- $stream = $objectContent->getStream();
- file_put_contents($tmpFile, $stream);
- } catch (Exceptions\IOError $e) {
+ } 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':