Vanthink-UED / vue-core-image-upload

a vue plugin for image to crop and upload

Home Page:http://vanthink-ued.github.io/vue-core-image-upload/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supporting dataURLtoBlob && dataURLtoFile

limdblur opened this issue · comments

Recommend that before call tryAjaxUpload(callback, isBinary, base64Code) function add some condition to parse base64Code to Blob. for instance:

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 });
}

dataURLtoFile(dataurl, filename) {
    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 File([u8arr], filename, {type:mime});
}

that will be nice for some server which only support blob upstream.