Chrome+IE默認支持粘貼剪切板中的圖片,可是我要發佈的文章存在word裏面,圖片多達數十張,我總不能一張一張複製吧?web
我但願打開文檔doc直接複製粘貼到富文本編輯器,直接發佈json
感受這個彷佛很困難,由於Ueditor自己不支持,粘貼後直接就是空白,這裏面必定有緣由。服務器
好,開始嘗試UMeditor,Chrome只能得到本地路徑,沒法讀取文件。網絡
https://ueditor.baidu.com/website/umeditor.html(有興趣能夠試試)app
難道就這麼失敗了?編輯器
不,可是我意外發現UMeditor居然支持粘貼word中的多張圖片(僅支持IE11,不支持IE10如下版本、以及Chrome等)ide
切換HTML,會看到你的圖片被組織成base64wordpress
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 (var i = 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 (var i = 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 (var i = 0, l = json.imgs.length; i < l; ++i)
{
var task = 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 (var i = 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("上傳完成");
var img = "<img src=\"";
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)
{
var up = this.fileMap[json.id];
up.postComplete(json);
delete up;//
};
this.File_PostProcess = function (json)
{
var up = this.fileMap[json.id];
up.postProcess(json);
};
this.File_PostError = function (json)
{
var up = 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)
{
var needUpdate = 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)
{
var json = 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);
};
服務端上傳代碼
using System;
using System.Web;
using System.IO;
namespace WordPasterCK4
{
publicpartialclassupload : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
string fname = Request.Form["UserName"];
int len = Request.ContentLength;
if (Request.Files.Count > 0)
{
DateTime timeNow = DateTime.Now;
string uploadPath = "/upload/" + timeNow.ToString("yyyyMM") + "/" + timeNow.ToString("dd") + "/";
string folder = Server.MapPath(uploadPath);
//自動建立目錄
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
HttpPostedFile file = Request.Files.Get(0);
//原始文件名稱,由控件自動生成。
string nameOri = file.FileName;
string ext = Path.GetExtension(nameOri).ToLower();
string filePathSvr = Path.Combine(folder, nameOri);
Response.Write(uploadPath + nameOri);
}
}
}
}
處理後的效果,可以批量上傳word中全部的圖片
圖片上傳後保存在服務器端
3、處理ueditor提供的uploadimage方法
客戶已經使用半年,沒有問題,很是有用,很是方便的功能
有須要的朋友能夠下載:http://blog.ncmem.com/wordpress/2019/08/07/ueditor複製word圖片粘貼上傳-2/