upload image from media library

if you want to upload images from the media library, you can use the following code.

Note: if you set the setting with upload images from the media library and local upload at the same time, local upload will be invalid.

editor.config.uploadImgFromMedia = function () {
  // 1. Call your own media library and display the UI page methods
  // ...
  // 2.Insert the image address returned by the media library into the editor, assuming imgUrl is the image address variable returned by the media

  editor.cmd.do( 'insertHTML', `<img src="${imgUrl}" style="max-width:100%;"/>` )


<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

        wangEditor demo
    <div id="div1">
        <p>Welcome to use <b>wangEditor</b> editor</p>
            <img src="http://www.wangeditor.com/imgs/logo.jpeg" />

    <script src="../dist/wangEditor.js"></script>
        var E = window.wangEditor
        var editor = new E('#div1')

        editor.config.uploadImgFromMedia = function () {
          // Call your own media library and display the UI page methods
          // Suppose you use the confirm method to simulate calling the media library
          const img = confirm('Call media library ')
          if (img) {
            const imgUrl = 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'
            // Insert the link to the media library callback into the editor using the editor.cmd.do method
              `<img src="${imgUrl}" style="max-width:100%;"/>`
          } else {

Copyright © wangEditor (2020 - present) all right reserved,powered by GitbookFile Modify: 2022-04-11 06:40:29

results matching ""

    No results matching ""