Ckeditor 添加自定义标题以上载图像
我目前正在尝试将集成到我的应用程序中 我面临上载图像功能的问题。。。我使用一个Node/Express后端,它使用JWT auth中间件,因此每个请求必须有一个Ckeditor 添加自定义标题以上载图像,ckeditor,ckeditor5,Ckeditor,Ckeditor5,我目前正在尝试将集成到我的应用程序中 我面临上载图像功能的问题。。。我使用一个Node/Express后端,它使用JWT auth中间件,因此每个请求必须有一个授权头才能通过 我想知道以下哪一项是可能的: 向组件添加自定义标题的方法 一种覆盖上载处理程序并调用自定义处理程序的方法,在这种方法中,我可以做任何事情 下面是我的代码 <CKEditor editor={ClassicEditor} data="<p>Add product description here
授权
头才能通过
我想知道以下哪一项是可能的:
- 向组件添加自定义标题的方法
- 一种覆盖上载处理程序并调用自定义处理程序的方法,在这种方法中,我可以做任何事情
<CKEditor
editor={ClassicEditor}
data="<p>Add product description here</p>"
onInit={(editor) => {
// You can store the "editor" and use when it is needed.
//console.log('Editor is ready to use!', editor);
}}
onChange={(event, editor) => {
const data = editor.getData();
this.handleData(data)
}}
config={{
ckfinder: {
uploadUrl: `${apiUrl}/upload/images/description`,
},
}}
/>
{
//您可以存储“编辑器”,并在需要时使用它。
//log('Editor已准备好使用!',Editor);
}}
onChange={(事件,编辑器)=>{
const data=editor.getData();
此.handleData(数据)
}}
配置={{
ckfinder:{
uploadUrl:`${APIRL}/upload/images/description`,
},
}}
/>
谢谢请在property onInit中使用此代码进行尝试
onInit={ editor => {
editor.plugins.get( 'FileRepository' ).createUploadAdapter = function( loader ) {
return new UploadAdapter( loader );
};
}}
之后,必须创建类UploadAdapter
class UploadAdapter {
constructor( loader ) {
// Save Loader instance to update upload progress.
this.loader = loader;
}
upload() {
const data = new FormData();
data.append('typeOption', 'upload_image');
data.append('file', this.loader.file);
return new Promise((resolve, reject) => {
axios({
url: `${API}forums`,
method: 'post',
data,
headers: {
'Authorization': tokenCopyPaste()
},
withCredentials: true
}).then(res => {
console.log(res)
var resData = res.data;
resData.default = resData.url;
resolve(resData);
}).catch(error => {
console.log(error)
reject(error)
});
});
}
abort() {
// Reject promise returned from upload() method.
}
}
上面的代码实际上让我使用图像上传,但图像没有上传。
data
const是一个空的FormData
对象,因此调用后没有上载图像。请记住,您必须返回已上载图像的url。您必须返回此数据('upload'=>TRUE,'url'=>')没有上载到服务器的图像,因此我无法返回有效的url。很抱歉,我忘记了这行代码->data.append('file',this.loader.file);,我已经编辑了前面的代码