首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用viewChild读取输入

使用viewChild读取输入
EN

Stack Overflow用户
提问于 2018-09-18 22:57:14
回答 1查看 66关注 0票数 0

我知道可以在头文件中验证这一点,但我无法读取文件的数据。我可以做些什么来访问数据,这样我就可以先读报头,再读正文?

代码语言:javascript
复制
<input type="file" #originalFile (change)="fileChosen($event)" accept=".bmp">
EN

回答 1

Stack Overflow用户

发布于 2018-09-18 23:16:26

您可以使用FileReader上传文件。为此,您可以这样做:

upload.component.ts

代码语言:javascript
复制
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'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52389424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档