Create a dedicated dropzone store uri

parent 5c60947c
...@@ -11,6 +11,7 @@ use Modules\Media\Events\FileWasLinked; ...@@ -11,6 +11,7 @@ use Modules\Media\Events\FileWasLinked;
use Modules\Media\Events\FileWasUnlinked; use Modules\Media\Events\FileWasUnlinked;
use Modules\Media\Events\FileWasUploaded; use Modules\Media\Events\FileWasUploaded;
use Modules\Media\Helpers\FileHelper; use Modules\Media\Helpers\FileHelper;
use Modules\Media\Http\Requests\UploadDropzoneMediaRequest;
use Modules\Media\Http\Requests\UploadMediaRequest; use Modules\Media\Http\Requests\UploadMediaRequest;
use Modules\Media\Image\Imagy; use Modules\Media\Image\Imagy;
use Modules\Media\Repositories\FileRepository; use Modules\Media\Repositories\FileRepository;
...@@ -113,6 +114,21 @@ class MediaController extends Controller ...@@ -113,6 +114,21 @@ class MediaController extends Controller
return response()->json($savedFile->toArray()); return response()->json($savedFile->toArray());
} }
public function storeDropzone(UploadDropzoneMediaRequest $request) : JsonResponse
{
$savedFile = $this->fileService->store($request->file('file'));
if (is_string($savedFile)) {
return response()->json([
'error' => $savedFile,
], 409);
}
event(new FileWasUploaded($savedFile));
return response()->json($savedFile->toArray());
}
public function update(File $file, Request $request) public function update(File $file, Request $request)
{ {
$data = $request->except(['filename', 'path', 'extension', 'size', 'id', 'thumbnails']); $data = $request->except(['filename', 'path', 'extension', 'size', 'id', 'thumbnails']);
......
<?php
namespace Modules\Media\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Modules\Media\Validators\MaxFolderSizeRule;
class UploadDropzoneMediaRequest extends FormRequest
{
public function rules()
{
return [
'file' => ['required', new MaxFolderSizeRule()],
];
}
public function authorize()
{
return true;
}
}
...@@ -29,6 +29,11 @@ $router->group(['middleware' => 'api.token'], function (Router $router) { ...@@ -29,6 +29,11 @@ $router->group(['middleware' => 'api.token'], function (Router $router) {
'as' => 'api.media.store', 'as' => 'api.media.store',
'middleware' => 'token-can:media.medias.create', 'middleware' => 'token-can:media.medias.create',
]); ]);
$router->post('file-dropzone', [
'uses' => 'MediaController@storeDropzone',
'as' => 'api.media.store-dropzone',
'middleware' => 'token-can:media.medias.create',
]);
$router->post('media/link', [ $router->post('media/link', [
'uses' => 'MediaController@linkMedia', 'uses' => 'MediaController@linkMedia',
'as' => 'api.media.link', 'as' => 'api.media.link',
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
backendUrl: '{{ config('asgard.core.core.admin-prefix') }}', backendUrl: '{{ config('asgard.core.core.admin-prefix') }}',
mediaGridCkEditor : '{{ route('media.grid.ckeditor') }}', mediaGridCkEditor : '{{ route('media.grid.ckeditor') }}',
mediaGridSelectUrl: '{{ route('media.grid.select') }}', mediaGridSelectUrl: '{{ route('media.grid.select') }}',
dropzonePostUrl: '{{ route('api.media.store') }}', dropzonePostUrl: '{{ route('api.media.store-dropzone') }}',
mediaSortUrl: '{{ route('api.media.sort') }}', mediaSortUrl: '{{ route('api.media.sort') }}',
mediaLinkUrl: '{{ route('api.media.link') }}', mediaLinkUrl: '{{ route('api.media.link') }}',
mediaUnlinkUrl: '{{ route('api.media.unlink') }}' mediaUnlinkUrl: '{{ route('api.media.unlink') }}'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment