I have recently learned about TinyMCE and has applied its version 4.3 into my project that help to save description.
It also requires images to be uploaded and displayed in the editor for the same purpose.
After searching I found it would have been easy for me to create a PHP or ASP.NET project which has a lot of help and plugins regarding TinyMCE but there are none or very less for J2EE or Servlet/JSP.
Currently my code stands here:
TinyMCE Script:
tinymce.init({
selector: '#description',
plugins: "image link imagetools codesample emoticons paste autoresize textcolor table preview",
menubar:false,
statusbar: false,
toolbar1: 'insertfile undo redo | styleselect | table | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'preview | forecolor backcolor | codesample emoticons',
automatic_uploads: true,
paste_data_images: true,
images_upload_base_path: '/uploaded/images',
file_picker_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '/uploadFile');
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(), fileName(blobInfo));
xhr.send(formData);
}
});
Servlet: Created and tested
FileUploader
servlet with path defined as/uploadFile
.
The servlet is working properly and returning JSON object { location : '/uploaded/images/filename.jpg' }
But the two codes here are not talking to each other.
Problem is TinyMCE is not having inbuilt File Explorer that can upload the separately before passing it to text-area, it is taking URL of image and passing it directly into <image>
tag without uploading the actual file.
Anyone can help me grab the TinyMCE Async Image Upload functionality? I tried going through links given like this and this but it did not seems to work.
Also I do not know how it has been marked duplicate as How to upload files to server using JSP/Servlet?
that's a very easy part, main question is How to call *FileUpload* servlet to upload images with TinyMCE in a Java Web App?
Let me know if any more explanation is required regarding this.
Asif