Directly submit Base64 encoded image data, too large, there will be a forwarding error in the background.
A good solution is to convert the Base64 encoded picture data to a blob (similar to file) and add it to the form for submission. Here's the code:
/** * @param base64codes * Image base64 encoded */function Sumitimagefile (base64codes) {var formData = new FormData () ; Here the other parameters in the form are also submitted together, if you do not need to submit additional parameters can be directly formdata parameterless constructor var url = "Upload url"; The Convertbase64urltoblob function converts the Base64 encoding to BLOB formdata.append ("ImageName", Convertbase64urltoblob (Base64codes)); The first parameter of the APPEND function is to get the parameter name of the data in the background, and the Name property of the input of the HTML tag is the same as the//ajax submit form if (window. XMLHttpRequest) {xmlhttp = new XMLHttpRequest (); } else if (window. ActiveXObject) {xmlhttp = new ActiveXObject (); } xmlhttp.open ("POST", url, True); Xmlhttp.send (FormData); Xmlhttp.onload = function (e) {if (This.status = =) {var obj = eval ("+ thi S.responsetext + ")"); var re = obj["return"]; } };} /** * Convert image URL data in base64 to BLOB * @param urldata * Base64 picture data represented by URL */function convertbase64urltoblob (urldata) {var Bytes=window.atob (urldata.split (', ') [1]); Remove the header of the URL and convert it to a byte//handle exception, converting the ASCII code less than 0 to a greater than 0 var ab = new ArrayBuffer (bytes.length); var ia = new Uint8array (AB); for (var i = 0; i < bytes.length; i++) {Ia[i] = bytes.charcodeat (i); } return new Blob ([ab], {type: ' Image/png '});}
Upload image file converted to blob