laraberg icon indicating copy to clipboard operation
laraberg copied to clipboard

Laraberg + laravel File manager (can't upload files)

Open igramnet opened this issue 2 years ago • 2 comments

Hi, I have a project with components: Laraberg, Laravel File Manager. In the editor I see the error "To edit this block, you need permission to upload media.".

image

What shall I configurate?

igramnet avatar Sep 10 '22 18:09 igramnet

const mediaUpload = ({filesList, onFileChange}) => { setTimeout(async () => {

            let data = new FormData;
            Array.from(filesList).map(file => {
                data.append('ficheiro', file);
            });

            const information = await axios.post("{{ route('sendimage') }}", data, {
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}',
                    'Content-Type': 'multipart/form-data'
                }
            }).then(function (response) {
                console.log(response.data)
                return response.data.msg;
            })


            const uploadedFiles = Array.from(filesList).map(file => {
                console.log(file)
                return {
                    id: file.id,
                    name: file.name,
                    url: information
                }
            })

            onFileChange(uploadedFiles)
        }, 1000)
    }
    Laraberg.init('[id_here]', {
        mediaUpload: mediaUpload,
        imageEditing: true,
        supportsLayout: true
    })

Munzambi-Miguel avatar Sep 18 '22 18:09 Munzambi-Miguel

Create your controller file set Method public function uploading(Request $request) {

    $path = 'app/public/editor_laraberge';
    $file = $request->hasFile('ficheiro') ? $request->file('ficheiro') : null;
    $new_image_name = 'editor' . date('Ymd') . uniqid('', true) . '.jpg';
    $upload = $file->move(storage_path($path), $new_image_name);

    return response()->json(['msg' => "storage/editor_laraberge/" . $new_image_name, 'file' => $file, 'request' => $request]);


}

Munzambi-Miguel avatar Sep 18 '22 18:09 Munzambi-Miguel

This issue has been automatically marked as stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Nov 18 '22 15:11 github-actions[bot]