Skip to content
Snippets Groups Projects
Commit 0a4142d5 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #19002 from UoM-ResPlat-DevOps/swift-streaming-download

Streaming download from Swift in files_external
parents 99e9c81c 8783eb99
No related branches found
No related tags found
No related merge requests found
...@@ -323,27 +323,24 @@ class Swift extends \OC\Files\Storage\Common { ...@@ -323,27 +323,24 @@ class Swift extends \OC\Files\Storage\Common {
switch ($mode) { switch ($mode) {
case 'r': case 'r':
case 'rb': case 'rb':
$tmpFile = \OCP\Files::tmpFile();
self::$tmpFiles[$tmpFile] = $path;
try { try {
$object = $this->getContainer()->getObject($path); $c = $this->getContainer();
} catch (ClientErrorResponseException $e) { $streamFactory = new \Guzzle\Stream\PhpStreamRequestFactory();
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); $streamInterface = $streamFactory->fromRequest(
return false; $c->getClient()
} catch (Exception\ObjectNotFoundException $e) { ->get($c->getUrl($path)));
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); $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; return false;
} } catch (\Guzzle\Http\Exception\BadResponseException $e) {
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); \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false; return false;
} }
return fopen($tmpFile, 'r');
case 'w': case 'w':
case 'wb': case 'wb':
case 'a': case 'a':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment