I am trying to read a user uploaded xml file in angular. Below is my code:
Component.ts:
convertFileToString(event){ this.uploadXML=event.target.files[0]; let fileReader = new FileReader(); fileReader.onload = (event) =>{this.finalUploadedXML=fileReader.result as String} fileReader.readAsText(this.uploadXML); console.log("The contents are:") console.log(this.finalUploadedXML); }
index.html
<input type="file" id="uploadInput" (change)="convertFileToString($event)" hidden>
But when i run this code, it gives me the following error:
Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'
I also modified the readAsText(this.uploadXML)
to readAsText(this.uploadXML.asInstanceOf[Blob])
but it seems that asInstanceOf
is not a known property of File type. So i tried changing the type of uploadXML
from File
to Blob
and the error still persists. What should i do?