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; + } }