From 17799122e225e6601e8e843189aa593fa10fdd13 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 25 Jun 2026 15:43:31 -0300 Subject: [PATCH] feat(attachments): update filename generation in AttachmentService to include file extension --- .../Attachable/Services/AttachmentService.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Domains/Attachable/Services/AttachmentService.php b/app/Domains/Attachable/Services/AttachmentService.php index ba065fd..e9a14b7 100644 --- a/app/Domains/Attachable/Services/AttachmentService.php +++ b/app/Domains/Attachable/Services/AttachmentService.php @@ -32,7 +32,7 @@ class AttachmentService $storedPath = Storage::disk('s3')->putFileAs( $this->directoryFromPath($normalizedPath), $file, - $key, + $this->buildStoredFilename($key, $file), ); if (! is_string($storedPath) || $storedPath === '') { @@ -120,4 +120,15 @@ class AttachmentService return AttachmentType::Other; } + + protected function buildStoredFilename(string $key, UploadedFile $file): string + { + $extension = strtolower($file->getClientOriginalExtension() ?: $file->extension() ?: ''); + + if ($extension === '') { + return $key; + } + + return $key.'.'.$extension; + } }