[Html] Image storage database, page directly read

 Upload a file, read the file information in the form of bytes (byte), encrypt the byte with base64, and store it in the database

byte[] mainImgBt = org.apache.commons.io.FileUtils.readFileToByteArray(mainImg);
sun.misc.BASE64Encoder encoder = new BASE64Encoder();
String mainImgEncode = encoder.encode(mainImgBt);

 

The page shows:

String imgSrc="data:image/jpg;base64,"+mainImgEncode
<img src=imgSrc>

 

refer to

https://www.lvtao.net/dev/php-image-data-url.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326854172&siteId=291194637