Upload a picture to base64, and report an error.

: ERROR TypeError: Failed to execute "readAsDataURL" on" FileReader": parameter 1 is not of type "Blob".
this is written in ionic

\\xx.html
<input type="file" (change)="selectImage(this.files)" accept="image/jpeg,image/png,image/jpg">
\\xx.ts
selectImage(file){
      var reader = new FileReader();
      reader.onload = function(file){
        // console.log(evt.currentTarget)
      }
      reader.readAsDataURL(file);
      console.log(reader.readAsDataURL(file));  
  }

Mar.11,2021

this.files is a class array, take the first reader.readAsDataURL (file [0]);


selectImage(event){
      let reader = new FileReader();
      let file = event.target.files[0];
      reader.readAsDataURL(file);
      reader.onload = function(){
        console.log(reader.result)
      }
    }

I want to ask how I convert blob to base64. The string I got is: url ("blob: http://localhost:8080/cc116c31-f8f1-47b1-a87b-96d948253495"). Please give me your advice

Menu