Nov 27, 2024
0
Level 1
Getting error while uploading image using tinymce
Hi, I am using TinyMCE. when i try to upload a image this error popup appears Cannot read properties of undefined (reading 'then')
this is my code
<script>
document.addEventListener('DOMContentLoaded', function () {
tinymce.init({
selector: '#body', // Target the textarea
plugins: 'image link code table lists',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
height: 400,
images_upload_url: 'admin/notification/upload',
// Custom image upload handler
images_upload_handler: function (blobInfo, success, failure) {
let xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '/admin/notification/upload');
const token = '{{ csrf_token() }}';
xhr.setRequestHeader("X-CSRF-Token", token);
xhr.onload = function() {
let json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
success(xhr.responseURL);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
/* enable title field in the Image dialog*/
image_title: true,
/* enable automatic uploads of images represented by blob or data URIs*/
automatic_uploads: true,
file_picker_types: 'image',
});
});
</script>
Please or to participate in this conversation.