public Map uploadPanorama(MultipartFile file) {
try {
String imgPattern = ".+(.JPEG|.jpeg|.JPG|.jpg|.png|.PNG)";
Pattern pattern = Pattern.compile(imgPattern);
String fileName = file.getOriginalFilename();
if (!pattern.matcher(fileName).find()) {
Preconditions.checkArgument(false, "只能上传图片");
}
String substring = fileName.substring(fileName.lastIndexOf("."));
//唯一名
String uuid = UUID.randomUUID().toString();
File path = new File(ResourceUtils.getURL("classpath:").getPath());
if (!path.exists()) {
path = new File("");
}
File upload = new File(path.getAbsolutePath(), "static/panorama/panos/");
if (!upload.exists()) {
upload.mkdirs();
}
if (!upload.exists()) {
upload.mkdirs();
}
File dest = new File(path.getAbsolutePath(), "static/panorama/panos/" + uuid + File.separator + "pano" + substring);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
file.transferTo(dest);
String panoramaPath = "//panorama//panos//" + uuid + "//pano" + substring;
Map<String, String> result = HttpUtil.cutPanorama(cutPanoramaPath, panoramaPath);
// Map<String, String> result = new HashMap<>();
result.put("imagePath", panoramaPath);
return result;
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException("程序出错!请稍后再试");
}
}
Java实现图片上传
最新推荐文章于 2025-08-16 16:10:31 发布
3532

被折叠的 条评论
为什么被折叠?



