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();
}
})
}
}
网友评论