TinyMCE 4.2 - Get the new (core) Image Tools to save (API) edited images as files?

淺唱寂寞╮ 提交于 2019-11-30 16:20:07

My code, it's works! If you modify the image and click confirm button then Image Tools will upload the new image to server automatic.

images_upload_handler: function(blobInfo, success, failure) {
            var xhr, formData;

            xhr = new XMLHttpRequest();
            xhr.withCredentials = false;
            xhr.open('POST', 
'<%=request.getContextPath()%>/fylerMedia?flyerID=<%=flyerID %>'); <<<<note that you must set your server-side upload hander.


            xhr.onload = function() {
              var json;

              if (xhr.status != 200) {
                failure('HTTP Error: ' + xhr.status);
                return;
              }

              json = JSON.parse(xhr.responseText);

              success(json[0].url); <<<<<return value, you can change the url of image.
            };

            formData = new FormData();
            formData.append('file', blobInfo.blob(), blobInfo.filename());

            xhr.send(formData);
        }

Hope it helps you!

You have to initiate the upload by invoking the

uploadImages()

method. see http://www.tinymce.com/wiki.php/api4:method.tinymce.Editor.uploadImages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!