From 15d3fe15c50880df6fddb5ccd7f8ab0463dd239f Mon Sep 17 00:00:00 2001 From: lxd <1004405501@qq.com> Date: Wed, 2 Apr 2025 15:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/http/HttpUtils.java | 17 ++++++++++------- .../InspectPatientController.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java index 3f902aa..5112872 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java @@ -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); } } diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java index d97a052..168d86c 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java @@ -939,7 +939,7 @@ public class InspectPatientController { } list.add(inspectPatientitemsSaveReqVO); patientitemsService.updatePatientitemInfo(list); - if(dataMap.get("personimg") != null|| dataMap.get("personimg") != "") + if(dataMap.get("personimg") != null) { String headurl = dataMap.get("personimg").toString(); String base64 = HttpUtils.getImageAsBase64(headurl);