Last active
May 22, 2017 21:16
-
-
Save rmcsharry/9ecf2b4741556c1db9eff315a971987a to your computer and use it in GitHub Desktop.
Code snippet for Angular2 typescript to convert file to Blob64 encoded string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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