File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed
eladmin-common/src/main/java/me/zhengjie/utils
eladmin-tools/src/main/java/me/zhengjie/service/impl Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change 5
5
import cn .hutool .core .util .IdUtil ;
6
6
import cn .hutool .poi .excel .BigExcelWriter ;
7
7
import cn .hutool .poi .excel .ExcelUtil ;
8
- import cn .hutool .poi .excel .ExcelWriter ;
9
8
import me .zhengjie .exception .BadRequestException ;
10
9
import org .springframework .web .multipart .MultipartFile ;
11
-
12
10
import javax .activation .MimetypesFileTypeMap ;
13
11
import javax .servlet .ServletOutputStream ;
14
12
import javax .servlet .http .HttpServletResponse ;
@@ -233,11 +231,10 @@ public static String getFileType(String type) {
233
231
return "视频" ;
234
232
} else return "其他" ;
235
233
}
234
+
236
235
public static String getFileTypeByMimeType (String type ) {
237
- // URLConnection.guessContentTypeFromName("." + type)
238
- // way 2 new MimetypesFileTypeMap().getContentType("."+ "txt")
239
236
String mimeType = new MimetypesFileTypeMap ().getContentType ("." + type );
240
- return mimeType .split ("\\ /" )[0 ];
237
+ return mimeType .split ("\\ /" )[0 ];
241
238
}
242
239
public static void checkSize (long maxSize , long size ) {
243
240
if (size > (maxSize * 1024 * 1024 )){
Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ public LocalStorageDTO findById(Long id) {
63
63
public LocalStorageDTO create (String name , MultipartFile multipartFile ) {
64
64
FileUtil .checkSize (maxSize , multipartFile .getSize ());
65
65
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 );
67
69
File file = FileUtil .upload (multipartFile , path + type + File .separator );
68
70
try {
69
71
name = StringUtils .isBlank (name ) ? FileUtil .getFileNameNoEx (multipartFile .getOriginalFilename ()) : name ;
You can’t perform that action at this time.
0 commit comments