johnk's avatar
Level 1

Integrate Tinymce with image upload

Hi, do you know how to integrate Tinymce with image upload with Laravel? With the code below the image link appears and when is clicked the user can select an image but after selecting an image it appears HTTP error: 405.

Do you know how to integrate Tinymce?


tinymce.init({
        selector:'textarea',
        plugins: 'image code link',
        toolbar: 'undo redo | image code',

        images_upload_handler: function (blobInfo, success, failure) {
            var xhr, formData;
            xhr = new XMLHttpRequest();
            xhr.withCredentials = false;
            xhr.open('POST', 'uploads/images');
            var token = '{{ csrf_token() }}';
            xhr.setRequestHeader("X-CSRF-Token", token);
            xhr.onload = function () {
                var json;
                if (xhr.status != 200) {
                    failure('HTTP Error: ' + xhr.status);
                    return;
                }
                json = JSON.parse(xhr.responseText);

                if (!json || typeof json.location != 'string') {
                    failure('Invalid JSON: ' + xhr.responseText);
                    return;
                }
                success(json.location);
            };
            formData = new FormData();
            formData.append('file', blobInfo.blob(), blobInfo.filename());
            xhr.send(formData);
        }
    });
});
0 likes
1 reply
machi7's avatar

maybe set the xhr.withCredentials to true..

xhr.withCredentials = true;

Please or to participate in this conversation.