Skip to content

Commit deae55c

Browse files
committed
Issue krayin#2328 has been fixed.
1 parent ca2b66e commit deae55c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/Webkul/Email/src/Repositories/AttachmentRepository.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\UploadedFile;
66
use Illuminate\Support\Facades\Storage;
7+
use Webklex\PHPIMAP\Attachment as ImapAttachment;
78
use Webkul\Core\Eloquent\Repository;
89
use Webkul\Email\Contracts\Attachment;
910
use Webkul\Email\Contracts\Email;
@@ -47,16 +48,30 @@ public function uploadAttachments(Email $email, array $data): void
4748
/**
4849
* Get the path for the attachment.
4950
*/
50-
private function prepareData(Email $email, UploadedFile $attachment): array
51+
private function prepareData(Email $email, UploadedFile|ImapAttachment $attachment): array
5152
{
52-
$path = 'emails/'.$email->id.'/'.$attachment->getClientOriginalName();
53+
if ($attachment instanceof UploadedFile) {
54+
$name = $attachment->getClientOriginalName();
5355

54-
Storage::put($path, $attachment->getContent());
56+
$content = file_get_contents($attachment->getRealPath());
57+
58+
$mimeType = $attachment->getMimeType();
59+
} else {
60+
$name = $attachment->name;
61+
62+
$content = $attachment->content;
63+
64+
$mimeType = $attachment->mime;
65+
}
66+
67+
$path = 'emails/'.$email->id.'/'.$name;
68+
69+
Storage::put($path, $content);
5570

5671
$attributes = [
5772
'path' => $path,
58-
'name' => $attachment->getClientOriginalName(),
59-
'content_type' => $attachment->getMimeType(),
73+
'name' => $name,
74+
'content_type' => $mimeType,
6075
'size' => Storage::size($path),
6176
'email_id' => $email->id,
6277
];

0 commit comments

Comments
 (0)