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); } }