Angular base 64符号化


この原理はとても简単で、しかし私は长い间/颜を覆って、ついに成功して、记录してhtml
<input type="file" id="file">
<input type="submit" (click)="turnToBase64()">


ts/js
  turnToBase64() {
     
    const getfile = document.getElementById('file') as HTMLInputElement;
    console.log(getfile);
    const reader = new FileReader();
    reader.readAsDataURL(getfile.files[0]);
    reader.onload = () => {
     
      console.log(reader.result as string);
    };
  }