Merge remote-tracking branch 'origin/main'

# Conflicts:
#	yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java
This commit is contained in:
Euni4U 2025-04-02 17:43:57 +08:00
commit 91b2ba55e5

View File

@ -12,9 +12,13 @@ import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Map;
@ -211,12 +215,11 @@ public class HttpUtils {
* 转换base64
* */
public static String getImageAsBase64(String imageUrl) throws IOException {
HttpResponse response = HttpRequest.get(imageUrl).execute();
if (response.isOk()) {
byte[] imageBytes = response.bodyBytes();
return Base64.encode(imageBytes);
} else {
throw new IOException("Failed to fetch image, HTTP status code: " + response.getStatus());
}
URL url = new URL(imageUrl);
BufferedImage image = ImageIO.read(url);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
byte[] imageBytes = baos.toByteArray();
return Base64.encode(imageBytes);
}
}