может ли кто-нибудь сказать мне, как отправить изображения на сервер с помощью quilljs.
Я попробовал это путь, но мне это не удалось.
Код: Выделить всё
const toolbarOptions = [
['bold', 'italic', 'underline'],
['blockquote'],
['image', 'video',],
];
const quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
function selectLocalImage() {
var input = document.createElement("input");
input.setAttribute("type", "file");
input.click();
// Listen upload local image and save to server
input.onchange = () => {
const file = input.files[0];
// file type is only image.
if (/^image\//.test(file.type)) {
this.saveToServer(file, "image");
} else {
console.warn("Only images can be uploaded here.");
}
};
}
function saveToServer(file) {
const fd = new FormData();
fd.append('image', file);
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://localhost/imagens', true);
xhr.onload = () => {
if (xhr.status === 200) {
// this is callback data: url
const url = JSON.parse(xhr.responseText).data;
insertToEditor(url);
}
};
xhr.send(fd);
}
function insertToEditor(url) {
// push image url to editor.
const range = quill.getSelection();
quill.insertEmbed(range.index, "image", url);
}
quill.getModule("toolbar").addHandler("image", () => {
this.selectLocalImage();
});
Может ли кто-нибудь помочь мне это исправить?
Я глубоко благодарен , просто изучите цели для новичка.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-quilljs