最佳答案
我有文件上传输入:
<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; 在 change 处理程序中。我如何用 ReactJS 做到这一点?