summernote使用onImageUpload上传图片的问题

Posted by baicai on April 23, 2016

最新版可能之前的方法失效了。经过查阅源码,发现需要注册callback,下面的方法可行:

$(document).ready(function() {
      $('#summernote').summernote({
        height: "200px",
        callbacks: {
          onImageUpload: function(files) {
            var $editor = $(this);
            var data = new FormData();
            data.append('fileup', files[0]);
            $.ajax({
              url: '/image/upload',
              method: 'POST',
              data: data,
              processData: false,
              contentType: false,
              success: function(url) {
                $editor.summernote('insertImage', url);
              }
            });
          }
        }
      });
    });

onImageUpload

Override image upload handler(default: base64 dataURL on IMG tag). You can upload image to server or AWS S3: more…</a>

// onImageUpload callback
$('#summernote').summernote({
  callbacks: {
    onImageUpload: function(files) {
      // upload image to server and create imgNode...
      $summernote.summernote('insertNode', imgNode);
    }
  }
});

// summernote.image.upload
$('#summernote').on('summernote.image.upload', function(we, files) {
  // upload image to server and create imgNode...
  $summernote.summernote('insertNode', imgNode);
});

下面有个demo:

https://output.jsbin.com/taxire