Base64 encoding and decoding of JS
English is this:
// Atob () decodes base64 Span style= "color: #008000;" >// Btoa () transcode the string to base64 var str = javascript ;window.btoa (str) // transcoding results "amf2yxnjcmlwda==" Window.atob ( " Span style= "color: #800000;" >amf2yxnjcmlwda== ) // decoding results "JavaScript"
Chinese needs a special look. transcoding encodeuricomponent and decodeURIComponent
Console.log (Window.btoa (encodeuricomponent ("haha")) are required
Console.log (decodeURIComponent (Window.atob ("JUU1JTKZJTG4JUU1JTKZJTG4")))
Juu1jtkzjtg4juu1jtkzjtg4
Ha ha
base64 to Blob object, file upload
/** * base64 to Blob object, file Upload * reprinted from: http://blog.csdn.net/hsany330/article/details/52575459 * @param datauri * @returns {Blob}*/ functionDatauritoblob (Datauri) {varbyteString = Atob (Datauri.split (', ') [1]); varmimestring = Datauri.split (', ') [0].split (': ') [1].split (';') [0]; varAB =NewArrayBuffer (bytestring.length); varIA =NewUint8array (AB); for(vari = 0; i < bytestring.length; i++) {Ia[i]=bytestring.charcodeat (i); } return NewBlob ([ab], {type:mimestring}); }
The relationship between the Blob,base64,url in JS