Base64 Transfer Image upload

Source: Internet
Author: User

not successful, but there is a certain reference/*** @param base64codes* Base64 encoding of images */function Sumitimagefile (base64codes) {//debuggerConsole.log (Convertbase64urltoblob (base64codes));var formData = new FormData (); The other parameters in the form are also submitted together, if you do not need to submit additional parameters can be directly formdata parameterless constructorsThe //convertbase64urltoblob function converts the Base64 encoding into a blobformdata.append ("ImageName", Convertbase64urltoblob (Base64codes)); The first parameter of the APPEND function is the parameter name of the background fetch data, and the same function as the Name property of the HTML tag inputtry{//Upload ("admin", "img", "Haode", formData);}catch (e) {Console.log ( e); alert ("The TMD is wrong again!" ");    }//ajax Submit Form$.ajax ({url:localstorage.imurl+ '/plugins/zatp?cmd=upload ',type: "POST",Data:formdata,dataType: "JSON",Processdata:false,//Tell jquery not to process the data sentContenttype:false,//Tell jquery not to set Content-type request headersuccess:function (data) {console.log (data);alert ("hahaha");        },xhr:function () {//XMLHttpRequest object that uses Ajax directly in the jquery functionvar xhr = new XMLHttpRequest ();Xhr.upload.addEventListener ("Progress", function (evt) {if (evt.lengthcomputable) {var percentcomplete = Math.Round (evt.loaded * 100/evt.total);Console.log ("committing."        +percentcomplete.tostring () + '% '); Print upload progress on the console                }}, False);return XHR;        }     });}/*** Convert image URL data in base64 to BLOB* @param urldata* Base64 image data represented in URL mode */function Convertbase64urltoblob (urldata) { var Bytes=window.atob (Urldata.split (', ') [1]); Remove the header from the URL and convert it to byte//Handle exception, convert ASCII code less than 0 to greater than 0var 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/jpeg '});}



Base64 Transfer Image upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.