Created
May 31, 2017 08:28
-
-
Save giscafer/59e8d19b6f1f9c51b84b9fb72bafa5d8 to your computer and use it in GitHub Desktop.
picture base64String to Blob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* base64 转 二进制文件 | |
* dataURL to blob, ref to https://gist.github.com/fupslot/5015897 | |
* @param dataURI | |
* @returns {Blob} | |
*/ | |
export function dataURItoBlob(dataURI) { | |
var byteString = atob(dataURI.split(',')[1]); | |
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; | |
var ab = new ArrayBuffer(byteString.length); | |
var ia = new Uint8Array(ab); | |
for (var i = 0; i < byteString.length; i++) { | |
ia[i] = byteString.charCodeAt(i); | |
} | |
return new Blob([ab], {type: mimeString}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment