From cf4cc4e061e8fd5f4a4e07eb38a3763dc7525293 Mon Sep 17 00:00:00 2001 From: Oskar-Mikael Date: Fri, 14 Jun 2024 12:28:08 +0200 Subject: [PATCH] Add image upload storage disk config var --- config/nova-tinymce-editor.php | 3 ++- src/Http/Controllers/TinyImageController.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config/nova-tinymce-editor.php b/config/nova-tinymce-editor.php index 5b5d1a7..ad71e06 100644 --- a/config/nova-tinymce-editor.php +++ b/config/nova-tinymce-editor.php @@ -57,7 +57,8 @@ 'upload_images' => [ 'enabled' => false, // Set true for enable images local upload 'folder' => 'images', - 'maxSize' => 2048, // KB + 'maxSize' => 2048, // KB, + 'disk' => 'public', ], ], ]; diff --git a/src/Http/Controllers/TinyImageController.php b/src/Http/Controllers/TinyImageController.php index 82a6a47..696c3e9 100644 --- a/src/Http/Controllers/TinyImageController.php +++ b/src/Http/Controllers/TinyImageController.php @@ -16,13 +16,13 @@ public function upload(Request $request): JsonResponse return response()->json(['error' => $validator->errors()->first()]); } - $imageFolder = config('nova-tinymce-editor.extra.upload_images.folder') ?? 'images'; + $imageFolder = config('nova-tinymce-editor.extra.upload_images.folder', 'images'); reset($_FILES); $temp = current($_FILES); if (is_uploaded_file($temp['tmp_name'])) { - $file = Storage::disk('public')->putFile($imageFolder, $temp['tmp_name']); + $file = Storage::disk(config('nova-tinymce-editor.extra.upload_images.disk', 'public'))->putFile($imageFolder, $temp['tmp_name']); - return response()->json(['location' => Storage::disk('public')->url($file)]); + return response()->json(['location' => Storage::disk(config('nova-tinymce-editor.extra.upload_images.disk', 'public'))->url($file)]); } else { return response()->json(['error' => 'Failed to move uploaded file.']); } @@ -31,7 +31,7 @@ public function upload(Request $request): JsonResponse public function validateRequest(Request $request): \Illuminate\Validation\Validator { - $maxSize = config('nova-tinymce-editor.extra.upload_images.maxSize') ?? 2048; + $maxSize = config('nova-tinymce-editor.extra.upload_images.maxSize', 2048); $validator = Validator::make($request->all(), [ 'file' => 'required|image|mimes:jpeg,png,jpg,gif|max:'.$maxSize, ]);