angular6 - 如何在 angular7 中将图像插入服务器而不是 Base64
问题描述
我目前正在我的 Angular 项目中使用 ngx-quill。我尝试使用编辑器添加图像,但编辑器上传图像 base64 编码。
editorText : string
editorForm: FormGroup
editorContent: any
editorStyle = {
height: '250px'
}
objectFormat = [
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
]
myObjStr:string
config = {
toolbar: {
container:
[
['image']
]
}
}
}
ngOnInit() {
this.editorForm = new FormGroup({
'editor': new FormControl(null)
})
有关将图像上传到服务器的图像处理过程的任何建议
解决方案
这不会为您上传图片,但如果图片已托管(如插入视频功能),则允许用户粘贴图片网址:
import { QuillModules, defaultModules } from 'ngx-quill';
export class MyComponent {
quillModules: QuillModules = {
toolbar: {
container: defaultModules.toolbar,
handlers: {
image: imageHandler
}
}
};
}
function imageHandler(this: any) {
imageHandler(this: any) {
const tooltip = this.quill.theme.tooltip;
const originalSave = tooltip.save;
const originalHide = tooltip.hide;
tooltip.save = function(this: any) {
const range = this.quill.getSelection(true);
const value = this.textbox.value;
if (value) {
this.quill.insertEmbed(range.index, 'image', value, 'user');
}
};
// Called on hide and save.
tooltip.hide = function (this: any) {
tooltip.save = originalSave;
tooltip.hide = originalHide;
tooltip.hide();
};
tooltip.edit('image');
tooltip.textbox.placeholder = "Embed URL";
}
}
<quill-editor [modules]="quillModules"></quill-editor>
推荐阅读
- ssl - 找不到 ngrok websocket 安全的证书
- php - (PHP) 带有授权标头的 file_get_contents
- django - 在 Django DetailView 中比较两个模型的值
- php - 如何通过 php 使用 Festival 文本到语音
- ms-access - Access 2016 如何使用变量的值而不是变量?
- ruby-on-rails - 未初始化的常量 ApplicationController (NameError)
- autodesk-model-derivative - Autodesk Forge 模型衍生 API:TranslationWorker-InternalFailure
- python - 无法使用折线图进行可视化
- rust - 从“拉”提交的索引写入树时,来自 libgit2 的“索引不受存储库支持”错误
- javascript - 带有 discord.js 的 node.js 中反应的多个输出