Skip to content

Commit 9dfd6f1

Browse files
authored
Merge pull request nextcloud#55654 from nextcloud/artonge/fix/do_not_happen_streams
2 parents c89ca89 + 00ec57e commit 9dfd6f1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,19 @@ 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-
$loadStream = new Psr7\AppendStream([$buffer, $psrStream]);
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 disk usage and does not require seeking on the
233+
// original stream.
234+
$buffer->rewind();
235+
$loadStream = new Psr7\AppendStream([$buffer, $psrStream]);
236+
}
237+
226238
$this->writeMultiPart($urn, $loadStream, $metaData);
227239
}
228240
} else {

0 commit comments

Comments
 (0)