Tag Archives: Uncaught DOMException

[Solved] Uncaught DOMException: Failed to execute ‘readAsDataURL‘ on ‘FileReader‘: The object is already busy

Uncaught DOMException: Failed to execute ‘readAsDataURL’ on ‘FileReader’: The object is already busy reading Blobs.

Error reason: a FileReader is reused

Solution: Create a FileReader each time

function read_files(){
    document.querySelector(openfiles[data_jigsaw_puzzle]).click();
    $(openfiles[data_jigsaw_puzzle]).change(function(){
        var reader_index = 0;
        var len = this.files.length;
        while(reader_index < len){
            var reader=new FileReader();
            reader.readAsDataURL(this.files[reader_index]);  
            reader.onload=function(){
                answers.push(this.result);
            }                                    
            reader_index++;
        } 
    })
}
read_files();