我知道可以在头文件中验证这一点,但我无法读取文件的数据。我可以做些什么来访问数据,这样我就可以先读报头,再读正文?
<input type="file" #originalFile (change)="fileChosen($event)" accept=".bmp">发布于 2018-09-18 23:16:26
您可以使用FileReader上传文件。为此,您可以这样做:
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'
}https://stackoverflow.com/questions/52389424
复制相似问题