1

我正在尝试拆分输入文件对象,但不工作

脚本

$('#imageUpload').change(function(){            
    readImgUrlAndPreview(this);
    function readImgUrlAndPreview(input){
        if (input.files && input.files[0]) {
             var reader = new FileReader();
             reader.onload = function (e) { 
                    var src_img = [];
                    src_img=$('#imageUpload')[0];                        
                    var comImgObj=dataURItoBlob(src_img);
                    $('#imagePreview').attr('src', e.target.result);
            };
            reader.readAsDataURL(input.files[0]);
        }
        else {
        var img = input.value;
        $('#imagePreview').attr('src',img);
        }
    }
});

function dataURItoBlob(dataURI) {
         var binary = atob(dataURI.split(',')[1]);
            var array = [];
            for(var i = 0; i < binary.length; i++) {
                array.push(binary.charCodeAt(i));
            }
            return new Blob([new Uint8Array(array)], {type: 'image/jpeg'});

}    

Jsfiddle
我收到这个错误

Uncaught TypeError: Object # has no method 'split'

4

0 回答 0