Skip to content

Instantly share code, notes, and snippets.

@lenconda
Created January 15, 2018 09:11
Show Gist options
  • Save lenconda/45c411b8669850adea3c9391b022c080 to your computer and use it in GitHub Desktop.
Save lenconda/45c411b8669850adea3c9391b022c080 to your computer and use it in GitHub Desktop.
拿到blob和转换
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