问题描述
我在项目中使用RichTextEditor。如何上传图片并使用上传的图片网址?
解决方法
<textarea id="rich_editor" placeholder="Type Message"></textarea>
<script>
let editorcfg = {}
editorcfg.file_upload_handler = uploadEditorImage();
let editor = new RichTextEditor("#rich_editor",editorcfg);
function uploadEditorImage(file,callback,optionalIndex,optionalFiles) {
let url = "/notification/image/upload";
let formData = new FormData();
formData.append("image",file);
axios.post(url,formData,{
headers: {
"Content-Type": "multipart/form-data"
}
}).then(response => {
if (response.data.success) {
Swal.fire(
"Success!","Image has been uploaded.","success"
);
callback(response.data.url);
}
});
}
</script>