Thursday, March 19, 2015

Convert datauri to blob - for uploading base64 data uri as image file

````
 function dataURItoBlob(dataURI, imgType) {
        var isSemicolonExist = (dataURI.indexOf(',') >= 0) ? true : false;
        alert(isSemicolonExist);
        var binary=[];
        if(isSemicolonExist)
            binary = atob(dataURI.split(',')[1]);
        else
            binary = atob(dataURI);
        var array = [];
        for(var i = 0; i < binary.length; i++) {
            array.push(binary.charCodeAt(i));
        }
        var blob = new Blob([new Uint8Array(array)], {type: imgType});
        return blob;
    }
````

No comments:

Post a Comment