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);
    }
    未闻花名
  • 相关阅读:
    codeforces 814B An express train to reveries
    codeforces 814A An abandoned sentiment from past
    codeforces 785D D. Anton and School
    codeforces 785C Anton and Fairy Tale
    codeforces 791C Bear and Different Names
    AOP详解
    Spring集成JUnit测试
    Spring整合web开发
    IOC装配Bean(注解方式)
    IOC装配Bean(XML方式)
  • 原文地址:https://www.cnblogs.com/duokexiao/p/13637059.html
Copyright © 2011-2022 走看看