如何使用Node.js从“ RichTextEditor”上传图像?

问题描述

我在项目中使用RichTextEditor。如何上传图片并使用上传图片网址?

http://joxi.ru/52aEa1jUkkw712

解决方法

<textarea id="rich_editor" placeholder="Type Message"></textarea>

<script>
   let editorcfg = {}
   editorcfg.file_upload_handler = uploadEditorImage();
   let editor = new RichTextEditor("#rich_editor",editorcfg);

   function uploadEditorImage(file,callback,optionalIndex,optionalFiles) {
       let url = "/notification/image/upload";
       let formData = new FormData();
       formData.append("image",file);

       axios.post(url,formData,{
           headers: {
              "Content-Type": "multipart/form-data"
           }
       }).then(response => {
            if (response.data.success) {
                 Swal.fire(
                     "Success!","Image has been uploaded.","success"
                 );

              callback(response.data.url);
           }
      });
  }    
</script>