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