Created
March 6, 2016 12:26
-
-
Save jesseky/e5e4710811c4d3d5fc35 to your computer and use it in GitHub Desktop.
Canvas DataURItoBlob
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 dataURItoBlob(dataURI) { | |
var byteString = atob(dataURI.split(',')[1]); | |
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; | |
var ab = new ArrayBuffer(byteString.length); | |
var dw = new DataView(ab); | |
for (var i = 0; i < byteString.length; i++) { | |
dw.setUint8(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