美文网首页
Base64图片转换

Base64图片转换

作者: 荒天帝886 | 来源:发表于2019-08-01 17:17 被阅读0次
    InputStream is = new FileInputStream("/Users/km005/Desktop/my_projects/javastudy/src/main/java/com/fzy/javastudy/java/day_0731/img/p1.jpg");
    int available = is.available();
    log.info("available - {}", available);
    byte[] data = new byte[available];
    is.read(data);
    byte[] encode = Base64.getEncoder().encode(data);
    String str = new String(encode);
    log.info("str - {}", str);
    
            let file = document.getElementById('file_input').files[0];
            var reader = new FileReader();
            if (file){
                reader.readAsDataURL(file);
                        //转换成功后
                reader.onloadend = function ()
                      {
                            //将转换结果赋值给img标签
                            console.log(reader.result);
                            let params = {};
                            params.data = reader.result;
                            axios.post('api/day_0731',params).then(res => {
                                if (res.data.code === 0){
                                    that.initImage();
                                }
                            })
                        }
                    }
    

    相关文章

      网友评论

          本文标题:Base64图片转换

          本文链接:https://www.haomeiwen.com/subject/hvecdctx.html