//convert a picture to Base64functiongetImgToBase64 (url,callback) {varCanvas = document.createelement (' Canvas '), CTX= Canvas.getcontext (' 2d '), IMG=NewImage; Img.crossorigin= ' Anonymous '; Img.onload=function() {canvas.height=Img.height; Canvas.width=Img.width; Ctx.drawimage (IMG,0,0); varDataurl = Canvas.todataurl (' image/png ')); Callback (Dataurl); Canvas=NULL; }; IMG.SRC=URL;}//convert base64 to filefunctiondataurltofile (dataurl, filename) {vararr = Dataurl.split (', '), MIME = Arr[0].match (/:(. *); [1], BSTR= Atob (arr[1]), n = bstr.length, U8arr =NewUint8array (n); while(n--) {U8arr[n]=bstr.charcodeat (n); } return NewFile ([U8arr], filename, {type:mime});}//convert a picture to Base64GetImgToBase64 (' Images/ruoshui.png ',function(data) {varMyFile = dataurltofile (data, ' testimgtestimgtestimg ')); Console.log (MyFile);});
JS,JQ Picture Conversion Base64 Base64 to file object