title: Converting Image to base64 string in Typescript
body: <p>I am trying to post base64 string to my api  from Angular 5</p>
  
  <p>First I have to convert it to base64 from image , After checking on internet and MDN I developed a method </p>
  
  <pre><code>  OnIDChange(event) {
      var file = event.target.files[0];
      var reader = new FileReader();
      reader.onloadend = this.handleReaderLoaded.bind(this, "Id");
      reader.readAsBinaryString(file);
    }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>    handleReaderLoaded(readerEvt:any, indicator: string) {
       var binaryString = readerEvt.target.result;
       if (indicator == "Id") {
         this.Model.IDPhoto = btoa(binaryString);
       }
    }
  </code></pre>
  
  <p>I have to store this base64 in Model Property to post it in api </p>
  
  <p>But in console it give error "Cannot read property 'result' of undefined" on  </p>
  
  <blockquote>
    <p>var binaryString = readerEvt.target.result;</p>
  </blockquote>
  
  <p>How can I convert image to base64 , if there is another more suitable way instead of this (any npm package or something else then let me know that too)</p>
  
  <p>Thanks in advance .</p>
  
  <p>Reference from MDN 
  <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader/onload" rel="noreferrer">MDN Link</a></p>