zoukankan      html  css  js  c++  java
  • vue 上传二进制图片

    1.前段代码

    <el-form-item label="证件照片" prop="idImage">
            <input @change='ss'  type="file">
    </el-form-item>

    2.script代码

    ss(event){
             var reader =new FileReader();//创建读取文件的方法
             var img1=event.target.files[0];
             reader.readAsDataURL(img1);//将文件已url的形式读入页面
              var that=this;
              reader.onload=function(e){ 
                that.ruleForm.idImage= reader.result; //把图片的二进制流付给表单ruleForm里面的idImage
          
              }
            // console.log();
          },

    3.我的后端用的是koa2

    用的是fs模块写入

    var base64Data = (ctx.request.body.idImage).replace("data:image/jpeg;base64,", " ");//如果是express框架的话只需要换成req.body.idImage
        console.log(base64Data);
        var binaryData = new Buffer(base64Data, "base64").toString("binary");
        fs.writeFile("out.png", binaryData, "binary", function(err) {
            if (err) {
                console.log(err);
            }
        });
  • 相关阅读:
    MobileNet V1 V2
    异常检测 与 One Class SVM
    异常检测
    图像分割
    1x1卷积核的作用
    迁移学习
    python
    图像分割
    图像分割
    Nagios
  • 原文地址:https://www.cnblogs.com/yu-hailong/p/8206130.html
Copyright © 2011-2022 走看看