Skip to content

Commit a528db8

Browse files
S3File: use dedicated temp stream to get size (#126)
1 parent 9aa106c commit a528db8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Models/S3File.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ class S3File extends File
1717

1818
public function calculateFilesize(): int
1919
{
20-
return $this->getReadableStream()->getSize();
20+
// Use a separate, immediately discarded, stream to get the file size
21+
// to avoid the main stream from being opened prematurely then timing
22+
// out before the file contents can be streamed.
23+
$stream = $this->buildReadableStream();
24+
$size = $stream->getSize();
25+
$stream->close();
26+
27+
return $size;
2128
}
2229

2330
public function setS3Client(S3Client $client): self

0 commit comments

Comments
 (0)