base64编码转图片


String data="data:image/jpeg;base64,/9j/4T....";
//        String   data="null";
     String   taskid="4028488c894831fd01894cbf0c6f0033";
        if(data.equals("")||data.equals("null")){
          System.out.println("无朝向照片可截取");

        }else {
            String  object = data.replace("data:image/jpeg;base64,", "");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String FTP_XSGL = ConfigUtil
                    .getProperties("FTP_XSGL");// IP地址
            String name = UUID.randomUUID() + ".jpg";
//            base64 解码
            byte[] b = DatatypeConverter.parseBase64Binary(object);
//            字节放入输入流
            InputStream in = new ByteArrayInputStream(b);
//            上传服务器
            String ftpPath = FtpUtil.uploadFile(name, in, FTP_XSGL);
            try {
                in.close();
                Date date = new Date();
                String sqlw="   select   * from  gw_pig_address_rw t    where t.dpt='GJCX'  and t.taskid='"+taskid+"' ";
                List> list = jdbcTemplate.queryForList(sqlw);
                if(list.size()>0){//走修改
                    String sqlr="update   gw_pig_address_rw set ipath=?,createtime=TO_DATE(?, 'YYYY-MM-DD hh24:mi:ss')  where taskid=?  and dpt='GJCX'";
                    jdbcTemplate.update(sqlr,new String[]{ftpPath,df.format(date),taskid});
                    System.out.println("更新朝向截图成功");
                }else {
                    String sql="INSERT INTO  gw_pig_address_rw  (ID,ipath,dpt,taskid,createtime)  VALUES (?,?,?,?,TO_DATE(?, 'YYYY-MM-DD hh24:mi:ss'))";
                    jdbcTemplate.update(sql,new String[]{UUID.randomUUID().toString(),ftpPath,"GJCX",taskid,df.format(date)});
                    System.out.println("添加朝向截图成功");
                }

                

//            jdbcTemplate.update(sql, UUID.randomUUID().toString(),ftpPath,"GJCX",new Date());

            } catch (IOException e) {

                throw new RuntimeException(e);
            }
        }

效果图展示:

 转载:在线base64 图片互转:

Base64/图片转换 - 在线工具

你可能感兴趣的:(笔记,windows)