I am quite newbie in angular7 and I just trying to get data from an input type file in the html file. I am not getting it. I got the name and different specifications of the file, but not the proper data of it.
The point is readystate doesnt change to 2, so result property never is fill it and I cant get the data so.
As far as I got it:
TS
onChange(event) {
if (event.target.files && event.target.files.length > 0) {
const file = event.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = this.saveImage(reader, event);
}
}
private saveImage (reader: FileReader, ev: ProgressEvent): any {
this.userInfo.Imagen = (reader.result as string).split(',')[1];
this.converted_image = this.domSanitizer.bypassSecurityTrustResourceUrl(this.base64 + this.userInfo.Imagen);
return null;
}
HTML
<input id="file-input" type="file" capture style="display:none" #fileInput (change)="onChange($event)"/>
But I dont recover any data at all.
Thanks mates.