Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'

前端 未结 4 2215
名媛妹妹
名媛妹妹 2021-02-02 08:18

I\'ve got a problem with a javascript Filereader which returns the error Uncaught TypeError: Failed to execute \'readAsDataURL\' on \'FileReader\': parameter 1 is not of type \'

4条回答
  •  孤城傲影
    2021-02-02 08:47

    i was getting a similar error when i would click the input but then instead of choosing an attachment, clicking cancel. so if I just wrapped the readAsDataURL call with an if statement checking if the file existed, it fixed it. see below.

    onSelectFile(event) {
        let reader = new FileReader();
        reader.onload = function(){
          let output: any = document.getElementById('blah');
          output.src = reader.result;
        }
        if(event.target.files[0]){
          reader.readAsDataURL(event.target.files[0]);
        }
    }
    

提交回复
热议问题