zoukankan      html  css  js  c++  java
  • 上传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);
    }
    未闻花名
  • 相关阅读:
    三层架构补充
    复习三层架构
    复习DOM、JQuery
    复习HTML CSS JavaScript
    Git在新电脑拉github 上的项目
    超全的IE兼容性问题及解决方案
    JS操作iframe
    attachEvent和addEventListener
    HTTP 方法:GET 对比 POST
    原生JS+ CSS3创建loading加载动画;
  • 原文地址:https://www.cnblogs.com/duokexiao/p/13637059.html
Copyright © 2011-2022 走看看