ShamiCanCode's avatar

CKeditor 419

Image upload gives 419 error

ClassicEditor
.create(document.querySelector('#editor'), {
                    ckfinder: {
                        uploadUrl: "{{ route('stories.editor-image.upload', ['_token=' => csrf_token()]) }}"
                    }
                })
                .catch(error => {
                    console.log(err)
                })

0 likes
3 replies
hupp's avatar

@shamicancode try to get the CSRF_TOKEN from the meta tag.

<meta name="csrf-token" content="{{ csrf_token() }}">

After this read from that element

var tokenElement = document.head.querySelector('meta[name="csrf-token"]');
    var token;

    if (tokenElement) {
        token = tokenElement.content;
    } else {
        console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
    }

Now you use that token variable. It should be worked.

semicolon24's avatar

@hupp

if i want to try this, where can i put

var tokenElement = document.head.querySelector('meta[name="csrf-token"]');
var token;

if (tokenElement) {
    token = tokenElement.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
hupp's avatar

{{ route('stories.editor-image.upload', ['_token=' => csrf_token()]) }} instead here csrf_token() you can use the token = tokenElement.content; basically you have to run test in js where you have done your question code. @semicolon24

Please or to participate in this conversation.