laraberg
laraberg copied to clipboard
Laraberg + laravel File manager (can't upload files)
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.".
What shall I configurate?
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
})
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]);
}
This issue has been automatically marked as stale because it has been open for 60 days with no activity.