Skip to content

Commit 8b5c04c

Browse files
committed
2.2 代码优化
1 parent d6fb61b commit 8b5c04c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import cn.hutool.core.util.IdUtil;
66
import cn.hutool.poi.excel.BigExcelWriter;
77
import cn.hutool.poi.excel.ExcelUtil;
8-
import cn.hutool.poi.excel.ExcelWriter;
98
import me.zhengjie.exception.BadRequestException;
109
import org.springframework.web.multipart.MultipartFile;
11-
1210
import javax.activation.MimetypesFileTypeMap;
1311
import javax.servlet.ServletOutputStream;
1412
import javax.servlet.http.HttpServletResponse;
@@ -233,11 +231,10 @@ public static String getFileType(String type) {
233231
return "视频";
234232
} else return "其他";
235233
}
234+
236235
public static String getFileTypeByMimeType(String type) {
237-
// URLConnection.guessContentTypeFromName("." + type)
238-
// way 2 new MimetypesFileTypeMap().getContentType("."+ "txt")
239236
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
240-
return mimeType.split("\\/")[0];
237+
return mimeType.split("\\/")[0];
241238
}
242239
public static void checkSize(long maxSize, long size) {
243240
if(size > (maxSize * 1024 * 1024)){

eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public LocalStorageDTO findById(Long id) {
6363
public LocalStorageDTO create(String name, MultipartFile multipartFile) {
6464
FileUtil.checkSize(maxSize, multipartFile.getSize());
6565
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
66-
String type = FileUtil.getFileTypeByMimeType(suffix);
66+
// 可自行选择方式
67+
// String type = FileUtil.getFileTypeByMimeType(suffix);
68+
String type = FileUtil.getFileType(suffix);
6769
File file = FileUtil.upload(multipartFile, path + type + File.separator);
6870
try {
6971
name = StringUtils.isBlank(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name;

0 commit comments

Comments
 (0)