title: angular convert file input to base64
body: <p>I am trying to parse a file input to base64 in my angular project.</p>
  
  <p>In my template I have:</p>
  
  <pre><code>&lt;input type="file" (change)="handleUpload($event)"&gt;
  </code></pre>
  
  <p>and then my function is this:</p>
  
  <pre><code>handleUpload(event) {
      const file = event.target.files[0];
      const reader = new FileReader();
      reader.readAsDataURL(event);
      reader.onload = () =&gt; {
          console.log(reader.result);
      };
  }
  </code></pre>
  
  <p>which gives me this error:</p>
  
  <pre><code>ERROR TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
      at _global.(anonymous function).(anonymous function) [as readAsDataURL] (webpack-internal:///./node_modules/zone.js/dist/zone.js:1323:60)
      at AccountFormComponent.handleUpload (account-form.component.ts:212)
      at Object.eval [as handleEvent] (AccountFormComponent.html:344)
      at handleEvent (core.js:13547)
      at callWithDebugContext (core.js:15056)
      at Object.debugHandleEvent [as handleEvent] (core.js:14643)
      at dispatchEvent (core.js:9962)
      at eval (core.js:10587)
      at HTMLInputElement.eval (platform-browser.js:2628)
      at ZoneDelegate.invokeTask (zone.js:421)
  </code></pre>