From 6d5555d5cd72275227b5b49fc3ff17756c5a8e28 Mon Sep 17 00:00:00 2001 From: Bryce Newbury Date: Thu, 12 Dec 2024 18:05:21 -0800 Subject: [PATCH] Fix S3 filenames that include a hash (#121) * Fix S3 filenames that include a hash * Use AWS stream wrapper to get S3 file sizes --- src/Models/S3File.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Models/S3File.php b/src/Models/S3File.php index fe99937..adee382 100644 --- a/src/Models/S3File.php +++ b/src/Models/S3File.php @@ -17,10 +17,7 @@ class S3File extends File public function calculateFilesize(): int { - return $this->getS3Client()->headObject([ - 'Bucket' => $this->getBucket(), - 'Key' => $this->getKey() - ])->get('ContentLength'); + return $this->getReadableStream()->getSize(); } public function setS3Client(S3Client $client): self @@ -39,16 +36,6 @@ public function getS3Client(): S3Client return $this->client; } - public function getBucket(): string - { - return parse_url($this->getSource(), PHP_URL_HOST); - } - - public function getKey(): string - { - return ltrim(parse_url($this->getSource(), PHP_URL_PATH), "/"); - } - protected function buildReadableStream(): StreamInterface { $this->getS3Client()->registerStreamWrapper();