1
2
3
4
5
6
7
8
9
public String base64(String imgFile) throws IOException {
File file = new File(imgFile);
try (FileInputStream fis = new FileInputStream(imgFile)) {
byte[] bytes = new byte[(int) file.length()];
fis.read(bytes);
String base64 = new String(Base64.getEncoder().encode(bytes), StandardCharsets.UTF_8);
return base64;
}
}