Created
January 15, 2018 09:11
-
-
Save lenconda/45c411b8669850adea3c9391b022c080 to your computer and use it in GitHub Desktop.
拿到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
function getObjectURL(file) { | |
var url = null; | |
if (window.createObjectURL != undefined) { | |
url = window.createObjectURL(file) | |
} else if (window.URL != undefined) { | |
url = window.URL.createObjectURL(file) | |
} else if (window.webkitURL != undefined) { | |
url = window.webkitURL.createObjectURL(file) | |
} | |
return url | |
} | |
function dataURLtoBlob(dataurl) { | |
var arr = dataurl.split(','), | |
mime = arr[0].match(/:(.*?);/)[1], | |
bstr = atob(arr[1]), n = bstr.length, | |
u8arr = new Uint8Array(n); | |
while (n--) { | |
u8arr[n] = bstr.charCodeAt(n); | |
} | |
return new Blob([u8arr], { type: mime }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment