0

I have an input (type file) that I have to read. My client must choose a 640x480 24-bit BMP file. I know it is possible to verify this in the header but I'm not able to read the data of the file. What can I do to get access to the data so I could read the header and then the body?

<input type="file" #originalFile (change)="fileChosen($event)" accept=".bmp">
Daniel
  • 77
  • 1
  • 2
  • 10

1 Answers1

0

You can use the FileReader to upload a file. For this you can do something like this:

upload.component.ts:

constructor() {
    this.reader = new FileReader();
    this.reader.onloadend = this.fileLoaded;
}

fileChosen($event){
    const file file = event.srcElement.files[0];
    // Read the file type with file.type
    // Read the file size with file.size

    // Read the file with:
    // this.reader.readAsArrayBuffer
    // this.reader.readAsText
    // this.reader.readAsDataURL
}

fileLoaded() {
    // You can access the uploaded file with 'this.reader.result'
}
Batajus
  • 5,831
  • 3
  • 25
  • 38