|
4 | 4 |
|
5 | 5 | use Illuminate\Http\UploadedFile; |
6 | 6 | use Illuminate\Support\Facades\Storage; |
| 7 | +use Webklex\PHPIMAP\Attachment as ImapAttachment; |
7 | 8 | use Webkul\Core\Eloquent\Repository; |
8 | 9 | use Webkul\Email\Contracts\Attachment; |
9 | 10 | use Webkul\Email\Contracts\Email; |
@@ -47,16 +48,30 @@ public function uploadAttachments(Email $email, array $data): void |
47 | 48 | /** |
48 | 49 | * Get the path for the attachment. |
49 | 50 | */ |
50 | | - private function prepareData(Email $email, UploadedFile $attachment): array |
| 51 | + private function prepareData(Email $email, UploadedFile|ImapAttachment $attachment): array |
51 | 52 | { |
52 | | - $path = 'emails/'.$email->id.'/'.$attachment->getClientOriginalName(); |
| 53 | + if ($attachment instanceof UploadedFile) { |
| 54 | + $name = $attachment->getClientOriginalName(); |
53 | 55 |
|
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); |
55 | 70 |
|
56 | 71 | $attributes = [ |
57 | 72 | 'path' => $path, |
58 | | - 'name' => $attachment->getClientOriginalName(), |
59 | | - 'content_type' => $attachment->getMimeType(), |
| 73 | + 'name' => $name, |
| 74 | + 'content_type' => $mimeType, |
60 | 75 | 'size' => Storage::size($path), |
61 | 76 | 'email_id' => $email->id, |
62 | 77 | ]; |
|
0 commit comments