1 InputSteam转Base64
/**
* InputStream转Base64
*
* @param inputStream
* @return
*/
public static String toBase64(InputStream inputStream) {
try {
//转换为base64
byte[] bytes = IOUtils.toByteArray(inputStream);
return Base64.getEncoder().encodeToString(bytes);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
2 调试代码
/**
* 获取Base64
*
* @return
* @throws IOException
*/
@GetMapping("/getBase64")
public String getBases64() throws IOException {
InputStream inputStream = new ClassPathResource("/img/logo.jpg").getInputStream();
return toBase64(inputStream);
}
3 图片地址
![](https://i-blog.csdnimg.cn/blog_migrate/a7ef19544b2080218fa3ab13c2425eed.png)
4 调试结果
![](https://i-blog.csdnimg.cn/blog_migrate/c91ace5589cb296e70262ab6746f2363.png)