File tree Expand file tree Collapse file tree
eladmin-common/src/main/java/me/zhengjie/utils
eladmin-tools/src/main/java/me/zhengjie/service/impl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import cn .hutool .core .util .IdUtil ;
66import cn .hutool .poi .excel .BigExcelWriter ;
77import cn .hutool .poi .excel .ExcelUtil ;
8- import cn .hutool .poi .excel .ExcelWriter ;
98import me .zhengjie .exception .BadRequestException ;
109import org .springframework .web .multipart .MultipartFile ;
11-
1210import javax .activation .MimetypesFileTypeMap ;
1311import javax .servlet .ServletOutputStream ;
1412import 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 )){
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments