test
This commit is contained in:
@@ -370,40 +370,16 @@ public class ArchiveFileController {
|
|||||||
String downLoadPath = path + fileNameServer;
|
String downLoadPath = path + fileNameServer;
|
||||||
String[] strings = fileName.split("\\.");
|
String[] strings = fileName.split("\\.");
|
||||||
String type = strings[strings.length - 1];
|
String type = strings[strings.length - 1];
|
||||||
|
boolean processedFromLocal = false;
|
||||||
|
|
||||||
// 检查是否通过URL访问
|
// 优先处理本地文件
|
||||||
if (url != null && !url.isEmpty()) {
|
File localFile = new File(downLoadPath);
|
||||||
// 使用流式处理,避免完整下载
|
if (localFile.exists()) {
|
||||||
try {
|
try (InputStream inputStream = new FileInputStream(localFile)) {
|
||||||
URL url1 = new URL(url);
|
|
||||||
HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection();
|
|
||||||
urlConnection.setConnectTimeout(10000); // 10秒超时
|
|
||||||
urlConnection.setReadTimeout(10000);
|
|
||||||
urlConnection.connect();
|
|
||||||
|
|
||||||
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
||||||
try (InputStream inputStream = urlConnection.getInputStream()) {
|
|
||||||
getImageMetadataFromStream(inputStream, fileName, type, mapList);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return json = AjaxJson.returnExceptionInfo("无法访问图片URL: " + url);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理URL图片失败: {}", e.getMessage());
|
|
||||||
return json = AjaxJson.returnExceptionInfo("处理URL图片失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 处理本地文件
|
|
||||||
File file = new File(downLoadPath);
|
|
||||||
if (!file.exists()) {
|
|
||||||
return json = AjaxJson.returnExceptionInfo("文件不存在: " + downLoadPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
try (InputStream inputStream = new FileInputStream(file)) {
|
|
||||||
getImageMetadataFromStream(inputStream, fileName, type, mapList);
|
getImageMetadataFromStream(inputStream, fileName, type, mapList);
|
||||||
|
|
||||||
// 获取文件大小
|
// 获取文件大小
|
||||||
int length = (int) (file.length() / 1024);
|
int length = (int) (localFile.length() / 1024);
|
||||||
VideoInfoUtils.setMapList("大小","length",length + "kb",mapList);
|
VideoInfoUtils.setMapList("大小","length",length + "kb",mapList);
|
||||||
|
|
||||||
// 判断是否数字加密了
|
// 判断是否数字加密了
|
||||||
@@ -419,12 +395,41 @@ public class ArchiveFileController {
|
|||||||
VideoInfoUtils.setMapList("数据加密", "signatureData", signatureMap.get("signatureData"), mapList);
|
VideoInfoUtils.setMapList("数据加密", "signatureData", signatureMap.get("signatureData"), mapList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
processedFromLocal = true;
|
||||||
|
log.info("成功从本地文件读取图片元数据: {}", downLoadPath);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理本地图片失败: {}", e.getMessage());
|
log.error("处理本地图片失败: {}", e.getMessage());
|
||||||
return json = AjaxJson.returnExceptionInfo("处理本地图片失败: " + e.getMessage());
|
processedFromLocal = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果本地文件不存在或处理失败,且提供了URL,则尝试从URL处理
|
||||||
|
if (!processedFromLocal && url != null && !url.isEmpty()) {
|
||||||
|
log.info("本地文件不存在或处理失败,尝试从URL读取: {}", url);
|
||||||
|
try {
|
||||||
|
URL url1 = new URL(url);
|
||||||
|
HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection();
|
||||||
|
urlConnection.setConnectTimeout(10000); // 10秒超时
|
||||||
|
urlConnection.setReadTimeout(10000);
|
||||||
|
urlConnection.connect();
|
||||||
|
|
||||||
|
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
|
try (InputStream inputStream = urlConnection.getInputStream()) {
|
||||||
|
getImageMetadataFromStream(inputStream, fileName, type, mapList);
|
||||||
|
}
|
||||||
|
log.info("成功从URL读取图片元数据: {}", url);
|
||||||
|
} else {
|
||||||
|
return json = AjaxJson.returnExceptionInfo("无法访问图片URL: " + url + ",响应码: " + urlConnection.getResponseCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理URL图片失败: {}", e.getMessage());
|
||||||
|
return json = AjaxJson.returnExceptionInfo("处理URL图片失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
} else if (!processedFromLocal) {
|
||||||
|
// 本地文件不存在且没有提供URL
|
||||||
|
return json = AjaxJson.returnExceptionInfo("文件不存在: " + downLoadPath);
|
||||||
|
}
|
||||||
|
|
||||||
json.put("list", mapList);
|
json.put("list", mapList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user