The relationship between the Blob,base64,url in JS

Source: Internet
Author: User
Tags base64

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

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.