CKEditor 图片上传无法使用 javascript

CKEditor Image Upload Not working using javascript

我在 java 和 java 脚本中工作,使用 ckeditor4.2 在上传图片时遇到一个问题。

我已经阅读了@Don Jones 对 Whosebug 本身的帮助

Start by registering your custom browser/uploader when you instantiate CKEditor. You can designate different URLs for an image browser vs. a general file browser.

<script type="text/javascript">
CKEDITOR.replace('content', {
    filebrowserBrowseUrl : '/browser/browse/type/all',
    filebrowserUploadUrl : '/browser/upload/type/all',
    filebrowserImageBrowseUrl : '/browser/browse/type/image',
    filebrowserImageUploadUrl : '/browser/upload/type/image',
    filebrowserWindowWidth  : 800,
    filebrowserWindowHeight : 500
});
</script>

Your custom code will receive a GET parameter called CKEditorFuncNum. Save it - that's your callback function. Let's say you put it into $callback.

When someone selects a file, run this JavaScript to inform CKEditor which file was selected:

window.opener.CKEDITOR.tools.callFunction(<?php echo $callback; ?>,url)

Where "url" is the URL of the file they picked. An optional third parameter can be text that you want displayed in a standard alert dialog, such as "illegal file" or something. Set url to an empty string if the third parameter is an error message.

CKEditor's "upload" tab will submit a file in the field "upload" - in PHP, that goes to $_FILES['upload']. What CKEditor wants your server to output is a complete JavaScript block:

$output = '<html><body><script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$callback.', "'.$url.'","'.$msg.'");</script></body></html>';
echo $output;

Again, you need to give it that callback parameter, the URL of the file, and optionally a message. If the message is an empty string, nothing will display; if the message is an error, then url should be an empty string.

现在的问题是

我已经按照下面的说明操作,服务器正在输出一个 JavaScript 块,与上面完全一样......问题是 CKEDITOR 没有对它做任何事情,文本只是显示在上传选项卡,而不是切换选项卡并采用 URL... 我希望图像显示在预览部分。是否有我需要确保已启用的回调配置或插件?

谢谢 请帮忙

@Ilia Shakitko 嘿,我得到的解决方案是。

Use CommonsMultipartFile for getting the uploaded file.then convert this file into bytes write it into BufferedOutputStream object.then upload it to your server (S3 / your own server) and then write below code

URL 将是下载的 url

String url;

          String script = "<script type='text/javascript'>" 
                        + " window.parent.CKEDITOR.tools.callFunction(1, '" + url + "', '');" + "</script>";

          PrintWriter out = null;
        try {
            out = res.getWriter();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
          out.println(script);