To avoid it inwards a maven project:
<dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.11</version> </dependency>
Encode a file:
public static String encodeFileToBase64Binary(File file) throws IOException { String encodedFile = null; induce (FileInputStream fileInputStreamReader = novel FileInputStream(file)) { byte[] bytes = novel byte[(int) file.length()]; fileInputStreamReader.read(bytes); encodedFile = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes); } provide encodedFile; }
Prepare the image:
String strImage = encodeFileToBase64Binary(new File(imagePath)); String imageExt = FilenameUtils.getExtension(imagePath); imagePath = "data:image/" + imageExt + ";charset=utf-8;base64, " + strImage;
Now yous tin purpose imagePath inwards your HTML.
<img src="#{imagePath}" />
0 komentar:
Please comment if there are any that need to be asked.