From 441320430f5f27a33a50d5ead63868aca22436f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:15:31 +0100 Subject: [PATCH] feat: create a seekable stream when reading. Allows http range requests which is necessary for video playback --- lib/s3storage.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/s3storage.php b/lib/s3storage.php index 39efc03d..ff7a2387 100644 --- a/lib/s3storage.php +++ b/lib/s3storage.php @@ -67,7 +67,7 @@ public function __construct($params) { $this->params = $params; } - protected function init() { + protected function init(): void { if ($this->connection) { return; } @@ -178,7 +178,10 @@ public function deleteObject($urn) { public function readObject($urn) { $this->init(); try { - return \fopen($this->getUrl($urn), 'r'); + $context = stream_context_create([ + 's3' => ['seekable' => true] + ]); + return \fopen($this->getUrl($urn), 'rb', false, $context); } catch (AwsException $ex) { throw new ObjectStoreOperationException($ex->getAwsErrorMessage(), $ex->getStatusCode(), $ex); } @@ -275,7 +278,11 @@ public function getVersion($urn, $versionId) { public function getContentOfVersion($urn, $versionId) { $this->init(); try { - return \fopen($this->getUrl($urn, $versionId), 'r'); + $context = stream_context_create([ + 's3' => ['seekable' => true] + ]); + + return \fopen($this->getUrl($urn, $versionId), 'rb', false, $context); } catch (AwsException $ex) { throw new ObjectStoreOperationException($ex->getAwsErrorMessage(), $ex->getStatusCode(), $ex); }