我整天都在尝试使CKEditor和React一起工作。除了图像,其他一切似乎都还不错。我
我已经有一种方法可以将图像上传到我的服务器(天蓝色)。我只需要知道如何使用React将其连接到CKEditor!我不断收到错误消息“未定义上传适配器。”
tokenization
我猜这与配置文件有关吗?我已经有上传文件并返回URL的功能,我只是不知道在React中将其添加到CKEditor中的位置。
答案 0 :(得分:0)
该错误表示未连接任何上传适配器。
首先,您需要实现自己的Custom Upload Adapter,该in this Stack Overflow response可以将图像上传到服务器。有一个示例http://somehost:9999
然后,使用onInit
方法将编辑器链接到上传适配器。像这样:
<CKEditor
editor={ClassicEditor}
data={this.state.body ? this.state.body : "<p>Body text…</p>"}
onInit={editor => {
// Connect the upload adapter using code below
editor.plugins.get("FileRepository").createUploadAdapter = function(loader) {
return new UploadAdapter(loader);
};
console.log("Editor is ready to use!", editor);
}}
onChange={(event, editor) => {
const data = editor.getData();
console.log({ event, editor, data }, "DATA");
}}
/>
代码中的 UploaderAdapter
是UploadAdapter类实现的名称。