优化图片

This commit is contained in:
马三炮 2025-04-25 15:37:22 +08:00
parent 64b8271532
commit 159122ae7f
1 changed files with 8 additions and 0 deletions

View File

@ -112,6 +112,14 @@ public class FileUploadUtils
assertAllowed(file, allowedExtension);
String fileName = extractFilename(file);
//把后缀都改成.png
int lastIndex = fileName.lastIndexOf('.');
if (lastIndex != -1) {
fileName = fileName.substring(0, lastIndex + 1) + "png";
}else {
fileName = fileName + "." + "png";
}
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
file.transferTo(Paths.get(absPath));