【发布时间】:2017-06-30 17:56:12
【问题描述】:
我有文件上传输入:
<input onChange={this.getFile} id="fileUpload" type="file" className="upload"/>
我以这种方式处理上传:
getFile(e) {
e.preventDefault();
let reader = new FileReader();
let file = e.target.files[0];
reader.onloadend = (theFile) => {
var data = {
blob: theFile.target.result, name: file.name,
visitorId: this.props.socketio.visitorId
};
console.log(this.props.socketio);
this.props.socketio.emit('file-upload', data);
};
reader.readAsDataURL(file);
}
如果我两次上传相同的文件,则不会触发上传事件。我该如何解决?对于简单的 js 代码,执行以下操作就足够了: this.value = null;在更改处理程序中。我怎样才能用 ReactJS 做到这一点?
【问题讨论】:
-
onChange={this.getFile.bind(this)}或 getFile = (e) => {
标签: html reactjs file-upload