html编辑器 直接粘贴图片,让富文本编辑器支持复制doc中多张图片直接粘贴上传...

Chrome+IE默认支持粘贴剪切板中的图片,可是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧

997b4f60d959493da8bfcf3f.html?web

我但愿打开文档doc直接复制粘贴到富文本编辑器,直接发布

997b4f60d959493da8bfcf3f.htmljson

感受这个彷佛很困难,由于Ueditor自己不支持,粘贴后直接就是空白,这里面必定有缘由。服务器

好,开始尝试UMeditor,Chrome只能得到本地路径,没法读取文件。网络

a396ca8c7deec5d693ada3a4b693f441.png

难道就这么失败了?编辑器

不,可是我意外发现UMeditor居然支持

997b4f60d959493da8bfcf3f.html粘贴word中的多张图片(仅支持IE11,不支持IE10如下版本、以及Chrome等)ide

切换HTML,会看到你的图片被组织成base64wordpress

abe325930ff40558808ad57ed14e4799.png

nice,机会来了,既然IE支持复制word中的多张图片直接粘贴base64,既然有了base64咱们就有办法上传转图片啦!post

那么咱们来改造Ueditor,让他支持IE11(总比没得用强吧)

打开你的ueditor.all.js(1.4.3版本如下行号根据本身使用的版本可能不一样)

1、注释掉14679行(暂时不明确有什么不良影响)

//执行默认的处理

//me.filterInputRule(root);

2、在28725行插入如下代码(若是是使用IE11粘贴会获得base64,先用占位符占位,再逐个把base64专成Blob文件并上传,上传完成再替换为你的img属性src为服务器图片url)

this.WordParser_PasteWord =function(json)

{

this.postType = WordPasteImgType.word;

this.EditorContent = json.word;

for(vari = 0, l = json.imgs.length; i < l; ++i)

{

this.addImgLoc(json.imgs[i]);

}

this.OpenDialogFile();

};

this.WordParser_PasteExcel =function(json)

{

this.postType = WordPasteImgType.word;

this.EditorContent = json.word;

for(vari = 0, l = json.imgs.length; i < l; ++i)

{

this.addImgLoc(json.imgs[i]);

}

this.OpenDialogFile();

};

this.WordParser_PasteHtml =function(json)

{

this.postType = WordPasteImgType.word;

this.InsertHtml(json.word);//

this.working =false;

};

this.WordParser_PasteFiles =function(json)

{

this.postType = WordPasteImgType.local;

for(vari = 0, l = json.imgs.length; i < l; ++i)

{

vartask =this.addImgLoc(json.imgs[i]);

task.PostLocalFile =true;//

}

this.OpenDialogFile();

};

this.WordParser_PasteImage =function(json)

{

this.OpenDialogPaste();

this.imgMsg.text("开始上传");

this.imgPercent.text("1%");

};

this.WordParser_PasteAuto =function(json)

{

this.postType = WordPasteImgType.network;

for(vari = 0, l = json.imgs.length; i < l; ++i)

{

this.addImgLoc(json.imgs[i]);

}

this.OpenDialogFile();

};

this.WordParser_PostComplete =function(json)

{

this.imgPercent.text("100%");

this.imgMsg.text("上传完成");

varimg ="%5C%22%22;

img += json.value;

img +="\" />";

this.InsertHtml(img);

this.CloseDialogPaste();

this.working =false;

};

this.WordParser_PostProcess =function(json)

{

this.imgPercent.text(json.percent);

};

this.WordParser_PostError =function(json)

{

this.OpenDialogPaste();

this.imgMsg.text(WordPasterError[json.value]);

this.imgIco.src =this.Config["IcoError"];

this.imgPercent.text("");

};

this.File_PostComplete =function(json)

{

varup =this.fileMap[json.id];

up.postComplete(json);

deleteup;//

};

this.File_PostProcess =function(json)

{

varup =this.fileMap[json.id];

up.postProcess(json);

};

this.File_PostError =function(json)

{

varup =this.fileMap[json.id];

up.postError(json);

};

this.Queue_Complete =function(json)

{

//上传网络图片

if(_this.postType == WordPasteImgType.network)

{

_this.GetEditor().setData(json.word);

}//上传Word图片时才替换内容

elseif(_this.postType == WordPasteImgType.word)

{

_this.InsertHtml(json.word);//

}

this.CloseDialogFile();

_this.working =false;

};

this.load_complete_edge =function(json)

{

_this.app.init();

};

this.state_change =function(json) {

if(json.value =="parse_document")

{

this.OpenDialogFile();

this.filesPanel.text("正在解析文档");

}

elseif(json.value =="process_data") {

this.filesPanel.text("正在处理数据");

}

elseif(json.value =="process_data_end")

{

this.filesPanel.text("");

}

};

this.load_complete =function(json)

{

varneedUpdate =true;

if(typeof(json.version) !="undefined")

{

this.setuped =true;

if(json.version ==this.Config.Version) {

needUpdate =false;

}

}

if(needUpdate)this.need_update();

//else { $.skygqbox.hide(); }

};

this.recvMessage =function(msg)

{

varjson = JSON.parse(msg);

if(json.name =="Parser_PasteWord") _this.WordParser_PasteWord(json);

elseif(json.name =="Parser_PasteExcel") _this.WordParser_PasteExcel(json);

elseif(json.name =="Parser_PasteHtml") _this.WordParser_PasteHtml(json);

elseif(json.name =="Parser_PasteFiles") _this.WordParser_PasteFiles(json);

elseif(json.name =="Parser_PasteImage") _this.WordParser_PasteImage(json);

elseif(json.name =="Parser_PasteAuto") _this.WordParser_PasteAuto(json);

elseif(json.name =="Parser_PostComplete") _this.WordParser_PostComplete(json);

elseif(json.name =="Parser_PostProcess") _this.WordParser_PostProcess(json);

elseif(json.name =="Parser_PostError") _this.WordParser_PostError(json);

elseif(json.name =="File_PostProcess") _this.File_PostProcess(json);

elseif(json.name =="File_PostComplete") _this.File_PostComplete(json);

elseif(json.name =="File_PostError") _this.File_PostError(json);

elseif(json.name =="load_complete") _this.load_complete(json);

elseif(json.name =="Queue_Complete") _this.Queue_Complete(json);

elseif(json.name =="load_complete_edge") _this.load_complete_edge(json);

elseif(json.name =="state_change") _this.state_change(json);

};

服务端上传代码

usingSystem;

usingSystem.Web;

usingSystem.IO;

namespaceWordPasterCK4

{

publicpartialclassupload: System.Web.UI.Page

{

protectedvoidPage_Load(objectsender, EventArgs e)

{

stringfname = Request.Form["UserName"];

intlen = Request.ContentLength;

if(Request.Files.Count > 0)

{

DateTime timeNow = DateTime.Now;

stringuploadPath ="/upload/"+ timeNow.ToString("yyyyMM") +"/"+ timeNow.ToString("dd") +"/";

stringfolder = Server.MapPath(uploadPath);

//自动建立目录

if(!Directory.Exists(folder)) Directory.CreateDirectory(folder);

HttpPostedFile file = Request.Files.Get(0);

//原始文件名称,由控件自动生成。

stringnameOri = file.FileName;

stringext = Path.GetExtension(nameOri).ToLower();

stringfilePathSvr = Path.Combine(folder, nameOri);

Response.Write(uploadPath + nameOri);

}

}

}

}

处理后的效果,可以批量上传word中全部的图片

f5654d1dcfac6e7b400cbe94461e6b10.png

图片上传后保存在服务器端

2fcdfabaf6189af057c159b60d9b5dfb.png

3、处理ueditor提供的uploadimage方法

客户已经使用半年,没有问题,很是有用,很是方便的功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值