Skip to content

Commit 8f43415

Browse files
committed
fixup! Merge pull request #55582 from nextcloud/jtr/chore-app-encryption-desc
1 parent cfec4c9 commit 8f43415

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,20 @@ public function writeObjectWithMetaData(string $urn, $stream, array $metaData):
222222
// buffer is fully seekable, so use it directly for the small upload
223223
$this->writeSingle($urn, $buffer, $metaData);
224224
} else {
225-
$psrStream->rewind();
226-
$this->writeMultiPart($urn, $psrStream, $metaData);
225+
if ($psrStream->isSeekable()) {
226+
// If the body is seekable, just rewind the body.
227+
$psrStream->rewind();
228+
$loadStream = $psrStream;
229+
} else {
230+
// If the body is non-seekable, stitch the rewind the buffer and
231+
// the partially read body together into one stream. This avoids
232+
// unnecessary disc usage and does not require seeking on the
233+
// original stream.
234+
$buffer->rewind();
235+
$loadStream = new Psr7\AppendStream([$buffer, $psrStream]);
236+
}
237+
238+
$this->writeMultiPart($urn, $loadStream, $metaData);
227239
}
228240
} else {
229241
if ($size < $this->putSizeLimit) {

0 commit comments

Comments
 (0)