package com.sinata.system.utils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import java.io.IOException;
|
import java.net.URL;
|
import java.util.Base64;
|
|
public class ImageToBase64 {
|
/**
|
* 网络图片转Base64
|
*
|
* @param imageUrl
|
* @return
|
* @throws IOException
|
*/
|
public static String convertImageToBase64(String imageUrl) {
|
try {
|
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(new URL(imageUrl)));
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
|
public static void main(String[] args) {
|
String imageUrl = "https://ja-medical-service.oss-cn-chengdu.aliyuncs.com/medical/tmp_8d18f8502484db9141a627d807dccb7c20250103015938.png";
|
String base64Image = convertImageToBase64(imageUrl);
|
System.out.println("Base64 Image: " + base64Image);
|
}
|
}
|