Trying to read simple text files but it does not seem to read it. When I select an image it works but when I select a text file or word doc it tells me: sanitizing unsafe URL value
This is the code I'm using:
onFilePicked(event: Event) {
const filePicked = (event.target as HTMLInputElement).files[0];
this.form.patchValue({ file: filePicked });
this.form.get('file').updateValueAndValidity();
const reader = new FileReader();
reader.onload = () => {
this.filePreview = reader.result;
};
reader.readAsDataURL(filePicked);
}
This is the HTML code
<div>
<button class="btn btn-outline-info btn-sm" type="button"
(click)="filePicker.click()">Pick File</button>
<input type="file" #filePicker (change)="onFilePicked($event)">
</div>
<div class="file-preview" *ngIf="filePreview !== '' && filePreview &&
form.get('file').valid">
<img [src]="filePreview" [alt]="form.value.title">
</div>
Does anyone spot the error, I have been reading other posts but they use jQuery. Any ideas to solve this error are welcome, thanks!
reader.readAsText(filePicked);from readAsUrl. I'm only new to all this and I'm trying to learn daily, will be careful next time with tags. @JonasLochmann