Copy image is nothing more than two ways, one is to upload pictures directly to a server, another converted into a binary code stream base64
current limiter chrome browser using the
first binary stream stored um-editor as an example:
Open umeditor.js found UM.plugins [ 'autoupload'], and then find autoUploadHandler method, wherein the code is commented.
Add the following code:
// determine whether the contents of the Clipboard contains text
// first explain why the judge is not empty text
// After ctrl + c word in the text or picture will return one kind (image / png) type or four kinds of objects (text / plain, text / html , text / rtf, image / png) type
// For 4 compatible format cases, we made the following determination
// the following code: e.originalEvent.clipboardData.items obtain contents of the clipboard
// After pasting text when text is not empty, but will return to the current text of the type of picture
// If there is text, then do not do any treatment, if only text, then paste the picture must be empty, including desktop picture or screenshot copy of the picture
var text = e.originalEvent.clipboardData.getData("text");
if(text == ""){
var items=e.originalEvent.clipboardData.items;
for (var i = 0, len = items.length; i < len; i++) {
var item = items[i];
if ( item.kind == 'file' && item.type.indexOf('image/') !== -1 ) {
var blob = item.getAsFile();
getBase64(blob, function( base64 ) {
// sendAndInsertImage (base64, me); uploaded to the server
setBase64Image (base64, me);
});
// prevent the default event, avoid duplication added;
e.originalEvent.preventDefault();
};
}
}
Two methods:
// insertion of image manipulation
function setBase64Image(base64,editor){
editor.execCommand('insertimage', {src: base64,_src: base64});
}
// get base64
function getBase64(blob, callback) {
var a = new FileReader();
a.onload = function(e) {callback(e.target.result);};
a.readAsDataURL(blob);
};
Results show:
details, refer to this article: http://blog.ncmem.com/wordpress/2019/08/07/ueditor-word%e5%9b%be%e7%89%87%e4%b8%8a % e4% bc% a0 /