使用spring将图像url添加到ckeditor

Add image url to ckeditor using spring

本文关键字:添加 ckeditor url 图像 spring 使用      更新时间:2023-09-26

我正在使用ckeditor上传数据库中的内容,一切都很顺利。我添加了config.filebrowserImageUploadUrl = 'uploadBlogFile'(我的控制器操作),但当我上传图像时,图像url没有添加到图像窗口上的text_field。。。

**My config.js**
CKEDITOR.editorConfig = function( config ) {
 // Define changes to default configuration here.
 // For complete reference see:
 // http://docs.ckeditor.com/#!/api/CKEDITOR.config
 // The toolbar groups arrangement, optimized for two toolbar rows.
 config.toolbarGroups = [
  { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
  { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
  { name: 'links' },
  { name: 'insert' },
  { name: 'forms' },
  { name: 'tools' },
  { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
  { name: 'others' },
  '/',
  { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
  { name: 'styles' },
  { name: 'colors' },
  { name: 'about' }
 ];
 // Remove some buttons provided by the standard plugins, which are
 // not needed in the Standard(s) toolbar.
 config.removeButtons = 'Underline,Subscript,Superscript,About';
 // Set the most common block elements.
 config.format_tags = 'p;h1;h2;h3;pre';
 // Simplify the dialog windows.
 config.removeDialogTabs = 'image:advanced;link:advanced';

 config.filebrowserImageUploadUrl = 'uploadBlogFile';

};
-------------------------------------------------------------
**My controller**
@RequestMapping(value = "/member/uploadBlogFile", method = RequestMethod.POST)
 @ResponseBody
 public Map<String, Object> uploadBlogFile(HttpSession session,HttpServletResponse response,
   @RequestParam MultipartFile upload) {
  User user = (User) session.getAttribute("user");
  String filePath = null;
  String imageSource = null;
  List<String> list = new ArrayList<String>();
  Map<String, Object> jsonMap = new HashMap<String, Object>();

  try {

   if (!upload.isEmpty()) {
    jsonMap.put("uploaded", 1);
    jsonMap.put("fileName", upload.getOriginalFilename());
    filePath = blogService.uloadBlogFile(user.getUserId(), upload);
   }
   if (filePath != null) {
    imageSource = DbConstants.AMAZON_S3_URL + DbConstants.SUFFIX
      + filePath;

   }
   if (imageSource != null && !imageSource.trim().isEmpty()) {
    list.add(imageSource);
    jsonMap.put("url",imageSource);
   }
    list.add(filePath);

   } catch (IOException e) {
   e.printStackTrace();
  } catch (FixitException e) {
   e.printStackTrace();
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  return jsonMap;
 }

我已经得到了这个问题的解决方案。这基本上是由于我的控制器上没有windowparent.CKEDITOR.tools.callFunction

我的控制器

在控制器上添加以下字符串,并作为json响应返回。

字符串路径="windowparent.CKEDITOR.tools.callFunction("+CKEditorFuncNum+",''"+url+",''""+"+"''");";