3

我将editorjs配置到我的应用程序中。我在上面安装了图像插件,以便我可以将图像上传到服务器。现在我的服务器上传图像并返回具有指定格式的 JSON,即,

{
  "success": 1,
  "file": {
    "url": "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg",
    // ... and any additional fields you want to store, such as width, height, color, extension, etc
  }
}

响应有 file->url 但仍然错误上传消息

错误图像

这是我的配置代码:

const editor = new EditorJS({
  /**
   * Id of Element that should contain Editor instance
   */
  holder: 'heditor',

  /** 
   * Available Tools list. 
   * Pass Tool's class or Settings object for each Tool you want to use 
   */
  tools: {
    header: {
      class: Header,
      inlineToolbar: ['link'],
      config: {
        placeholder: 'Title...'
      }
    },
    paragraph: {
      class: Paragraph,
      inlineToolbar: true,
    },
    image: {
      class: ImageTool,
      config: {
        endpoints: {
          accept: 'image/*',
          byFile: $('#heditor').data('url'), // Your backend file uploader endpoint
          byUrl: $('#heditor').data('url'), // Your endpoint that provides uploading by Url
        },
        additionalRequestHeaders: {
          'x-auth-token': $('#heditor').data('token'),
        }
      }
    },
    linkTool: {
      class: LinkTool,
      config: {
        endpoint: 'http://localhost:8008/fetchUrl', // Your backend endpoint for url data fetching
      }
    },
    inlineCode: {
      class: InlineCode,
      shortcut: 'CMD+SHIFT+M',
    },
    Marker: {
      class: Marker,
      shortcut: 'CMD+SHIFT+M',
    },
    embed: Embed,

    list: {
      class: List,
      inlineToolbar: true
    }
  },

  /**
     * This Tool will be used as default
     */
  // initialBlock: 'paragraph',

  /**
   * Initial Editor data
   */
  data: {
    blocks: [
      {
        type: "header",
        data: {
          text: "Title of your story",
          level: 2
        }
      },
      {
        type: 'paragraph',
        data: {
          text: 'Hey. Meet the new Story Editor. On this page you can start writing your story — try to edit this text...'
        }
      }
    ]
  },
  onReady: function () {
    saveButton.click();
  },
  onChange: function () {
    console.log('something changed');
  }
});

/**
     * Saving example
     */
saveButton.addEventListener('click', function () {
  editor.save().then((savedData) => {
    $("#output").html(savedData);
  });
});

我做错了什么有人可以帮忙吗?

4

0 回答 0