使用spring将图像URL添加到ckeditor

时间:2015-11-23 06:52:30

标签: javascript spring

我使用ckeditor在数据库中上传内容,一切都很顺利。我添加了config.filebrowserImageUploadUrl = 'uploadBlogFile'(我的控制器操作)'但是当我上传图片时,图片网址没有添加到图片窗口上的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;

 }

0 个答案:

没有答案