Skip to content

Instantly share code, notes, and snippets.

@rmcsharry
Last active May 22, 2017 21:16
Show Gist options
  • Save rmcsharry/9ecf2b4741556c1db9eff315a971987a to your computer and use it in GitHub Desktop.
Save rmcsharry/9ecf2b4741556c1db9eff315a971987a to your computer and use it in GitHub Desktop.
Code snippet for Angular2 typescript to convert file to Blob64 encoded string
onFileChange(event){
let files = event.srcElement.files;
this.selectedFile = files[0];
if (files && this.selectedFile) {
let reader = new FileReader();
reader.onload = this._handleReaderLoaded.bind(this);
reader.readAsBinaryString(this.selectedFile);
}
}
_handleReaderLoaded(readerEvt) {
var binaryString = readerEvt.target.result;
this.selectedFileAsBase64String = btoa(binaryString);
console.log(btoa(binaryString));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment