Base64图片转换

2019-08-01  本文已影响0人  荒天帝886
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();
                            }
                        })
                    }
                }
上一篇下一篇

猜你喜欢

热点阅读