惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
美团技术团队
H
Help Net Security
G
Google Developers Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
M
MIT News - Artificial intelligence
腾讯CDC
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
I
InfoQ
博客园 - 司徒正美
A
About on SuperTechFans

博客园 - Xproer-松鼠

PHP实现视频文件上传完整实例 ueditor 富文本编辑器粘贴图片时让图片居中 UEditor富文本编辑器图片粘贴和上传问题 vue项目中使用tinymce富文本编辑器实现图片上传/粘贴格式 富文本编辑器复制word文档中的图片 富文本编辑器:自己实现图片上传功能和图片粘贴上传(kindeditor) 前端上传文件或者上传文件夹 前端实现文件上传(点击+拖拽) HTML5应用之文件拖拽上传 使用HTML5实现多文件上传 HTML5 文件上传的2种方式 html5实现文件批量上传组件 HTML5文件上传操作 html5中怎么实现多文件上传功能 HTML5 进阶系列:文件上传下载 html实现上传 大文件分片上传 【前后台完整版】大文件分片上传 大文件、视频分片上传,断点续传
TinyMCE富文本编辑器粘贴图片自动上传问题解决
Xproer-松鼠 · 2023-12-27 · via 博客园 - Xproer-松鼠

TinyMCE 编辑器支持粘贴图片,但是自动会将图片转换成 base64 编码,这样将内容提交到后台,数据会很大。

图 | TinyMCE

本文内容配置TinyMCE(版本:5.10.0)向编辑器中粘贴图片自动上传到后台,以下为配置代码:

tinymce.init({
selector: '#textarea',
plugins: 'preview autolink directionality visualchars fullscreen image link template code table pagebreak nonbreaking anchor insertdatetime advlist lists wordcount autoresize imagetools paste',
paste_data_images: true,
//粘贴图片后,自动上传
urlconverter_callback: function(url, node, on_save, name) {
console.log('图片链接', url );
return url;
},
images_upload_handler: function (blobInfo, succFun, failFun) {
var xhr, formData;
var file = blobInfo.blob();//转化为易于理解的file对象
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'upload.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failFun('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
//failFun('Invalid JSON: ' + xhr.responseText);
failFun( '上传失败' );
return;
}
succFun(json.location);
};
formData = new FormData();
formData.append('file', file, file.name );//此处与源文档不一样
xhr.send(formData);
}
});

配置项
plugins中添加paste;
paste_data_images设置为true;
添加:

urlconverter_callback: function(url, node, on_save, name) {
console.log('图片链接', url );
return url;
}
以下是配置后粘贴图片效果,和上传效果一样。

图 | TinyMCE

参考文章:http://blog.ncmem.com/wordpress/2023/12/27/tinymce%e5%af%8c%e6%96%87%e6%9c%ac%e7%bc%96%e8%be%91%e5%99%a8%e7%b2%98%e8%b4%b4%e5%9b%be%e7%89%87%e8%87%aa%e5%8a%a8%e4%b8%8a%e4%bc%a0%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3/

欢迎入群一起讨论