1

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.

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60

1 Answers1

0

Finally... Quite odd and hoping this answer help you all or, at least, give you a clue about this situation.

Chrome version, from 73 to 75 (fixed in it) has a problem when an event collides with a debugger command or break point by IDE (debugger command in fact).

The solution is just eliminate any debugger command in the cycle of raising and launching the event and its event method.

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60
  • The idea original is coming from here: https://stackoverflow.com/questions/44091937/why-is-this-filereader-onload-not-firing/55703594#55703594 (check the reputation of user who post it). But for me is not still working. I delete breakpoint from when I instance the filereader until onload method is fired and now is working for me. – Kenzo_Gilead Apr 25 '19 at 11:05
  • As far you are criticizing my answer without checking it. Please rate it (with an upvote) for the question, for taking care of posting the extendend answer, and researching again for finding the source as you required... I think is quite far doing that for helping and reward the efford of user of our community :) – Kenzo_Gilead Apr 25 '19 at 11:08
  • Really man? It is a bug known for Chrome. And it is working for me, resolving the problem... Dont be a child... – Kenzo_Gilead Apr 25 '19 at 11:22
  • You know we are speaking about a reported and recognized error in chrome... And you are voting down... You are amazing... Really. The best! – Kenzo_Gilead Apr 25 '19 at 16:19