angular - 如何在 CKEditor5 Angular 中编写自定义上传适配器
问题描述
我正在寻找在 CKEditor5 中构建用于上传图像的自定义上传适配器。
我的代码是:
零件:
import { Component } from '@angular/core';
import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import Base64UploadAdapter from '@ckeditor/ckeditor5-
upload/src/base64uploadadapter';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'ckeditor';
public Editor = ClassicEditor;
ckconfig = {
// include any other configuration you want
extraPlugins: [ this.TheUploadAdapterPlugin ]
};
TheUploadAdapterPlugin(editor) {
console.log('TheUploadAdapterPlugin called');
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
// return new UploadAdapter(loader, '/image');
return "hello";
};
}
class UploadAdapter {
loader; // your adapter communicates to CKEditor through this
url;
constructor(loader, url) {
this.loader = loader;
this.url = url;
console.log('Upload Adapter Constructor', this.loader, this.url);
}
upload() {
return new Promise((resolve, reject) => {
console.log('UploadAdapter upload called', this.loader, this.url);
console.log('the file we got was', this.loader.file);
resolve({ default: 'http://localhost:8080/image/1359' });
});
}
abort() {
console.log('UploadAdapter abort');
}
}
}
我收到错误消息“意外的令牌。应有构造函数、方法、访问器或属性。” 对于 UploadAdapter 类。知道为什么吗?
此外,图像上传似乎无法以这种方式工作。是否有任何在线可用的实施示例。我找不到任何东西。
解决方案
推荐阅读
- apache-camel - 骆驼处理后通过 SFTP 移动文件是否有文件大小限制?
- sqlite - 加密 SQLite3 数据库的密码限制是什么?
- python - 如何在matplotlib的主图之外绘制箭头和矩形(用于蛋白质sec结构)?
- amazon-web-services - 归档 dynamodb 记录的最佳方式?
- node.js - 配置快速网关以使用 redis
- python - Pymongo 抛出“操作失败:密钥太长”
- reactjs - React Native - 使用 useState 传递 API 响应数据的问题
- nginx - Nginx 反向代理 - 请求基本身份验证凭据并将它们传递给目标 API
- javascript - React 视频元素无法正常工作
- c# - 在 Azure 函数上设置 RequestOptions CosmosDB 输出绑定