其他分享
首页 > 其他分享> > 上传16进制文件

上传16进制文件

作者:互联网

<input single ref={ref => this.handler = ref} id="icon-button-file" onChange={this.fileChanges} accept={accept} type="file" style={{ display: 'none' }} /> <label htmlFor="icon-button-file"> <IconButton color="primary" aria-label="upload picture" component="span"> <IconUpload /> </IconButton> {show&& <Typography variant="h7" component="span" color="primary" gutterBottom> 点击上传 </Typography>} </label>       fileChanges = (event) => { let source = event.target.files; this.setState({ loading: true }); console.log(source) if (source.length > 0) { const reader = new FileReader();// reader.onload = rest => { const fix = this.buf2hex(rest.target.result); console.log(fix) let file = source[0]; let hf = file.name; const len = hf.lastIndexOf('.'); console.log(len) hf = hf.substring(len + 1); console.log(hf) this.wrapFiles({ value: fix, key: file.type, extra: hf, remark: file.name }); }; reader.readAsArrayBuffer(source[0]); } }       buf2hex = (buffer) => { // buffer is an ArrayBuffer console.log(buffer) return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(''); }         wrapFiles = (input) => { const { onChange } = this.props; this.setState({ file: input, loading: false }); if (onChange) onChange(input); }

标签:console,进制,16,上传,source,file,onChange,hf,log
来源: https://www.cnblogs.com/duokexiao/p/13637059.html