人员下发修改

This commit is contained in:
fl 2025-07-04 13:14:42 +08:00
parent 4597eb4368
commit c90848855e
1 changed files with 32 additions and 5 deletions

View File

@ -175,11 +175,7 @@ public class IntelligentLibraryUtil {
public static String addPersonImage(PersonImageVo param){
try {
// 假设我们有一个URL
URL url = new URL(param.getImagePath());
// 将URL转换为File
File file = new File(url.getFile());
File[] imageData = {file}; //
File[] imageData = convertUrlToFile(param.getImagePath()); //
DigestAuthClient client = new DigestAuthClient(DIGEST_USER, md5(DIGEST_PWD));
// 定义需要添加的表单数据
Map<String, String> formData = new HashMap<>();
@ -192,6 +188,37 @@ public class IntelligentLibraryUtil {
}
}
public static File[] convertUrlToFile(String imageUrl) throws Exception {
// 打开URL输入流
try (InputStream in = new URL(imageUrl).openStream()) {
// 创建临时文件保留原始扩展名
String suffix = getExtensionFromUrl(imageUrl);
File tempFile = File.createTempFile("image-", suffix);
tempFile.deleteOnExit(); // 程序退出时自动删除
// 写入到临时文件
try (FileOutputStream out = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
return new File[]{tempFile};
}
}
// 从URL中提取后缀名比如 ".jpg", ".png"
private static String getExtensionFromUrl(String url) {
String lowerCaseUrl = url.toLowerCase();
if (lowerCaseUrl.endsWith(".jpg") || lowerCaseUrl.endsWith(".jpeg")) return ".jpg";
if (lowerCaseUrl.endsWith(".png")) return ".png";
if (lowerCaseUrl.endsWith(".gif")) return ".gif";
if (lowerCaseUrl.endsWith(".bmp")) return ".bmp";
return ".tmp"; // 默认后缀
}
public static File[] convertImageUrlToFile(String imageUrl, int width, int height) throws IOException {
// 从给定的 URL 获取图像数据
try (InputStream inputStream = new URL(imageUrl).openStream()) {