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);
    }
    未闻花名
  • 相关阅读:
    求公约数和比值
    HTML5 文件上传
    js判断是pc还是移动端
    ssm整合
    如何获取数据表中自增主键的值
    MyBatis全局配置文件标签详解
    MyBatis介绍及使用
    基于Spring MVC的文件上传和下载功能的实现
    Spring IOC容器交给application域对象管理
    SpringMVC的简单介绍及使用
  • 原文地址:https://www.cnblogs.com/duokexiao/p/13637059.html
Copyright © 2011-2022 走看看