Skip to content

Commit

Permalink
Add image upload storage disk config var
Browse files Browse the repository at this point in the history
  • Loading branch information
Oskar-Mikael committed Jun 14, 2024
1 parent b637510 commit cf4cc4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/nova-tinymce-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
];
8 changes: 4 additions & 4 deletions src/Http/Controllers/TinyImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.']);
}
Expand All @@ -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,
]);
Expand Down

0 comments on commit cf4cc4e

Please sign in to comment.