Data protocol URL size limitations

后端 未结 11 1526
夕颜
夕颜 2020-11-22 15:01

Is there any size limitation for \"data:\" URL scheme values? I\'m interested in limitations in popular web browsers. In other words, how long can data:image/jpg;base6

11条回答
  •  星月不相逢
    2020-11-22 15:39

    2017 answer is: convert data: to blob with function: dataURLtoBlob

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

    then create blob url

    var temp_url = window.URL.createObjectURL(blob);
    

    then use it in new window if you need.

    var redirectWindow = window.open('');
    redirectWindow.document.write('')      
    

    works with big files in chrome/firefox 2017

提交回复
热议问题