From 03304325d5d2104b3aff45b1938ff8411df2c277 Mon Sep 17 00:00:00 2001 From: many2many <6168830@qq.com> Date: Mon, 20 May 2024 13:12:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lk/paopao/service/AttachService.java | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/lk/paopao/service/AttachService.java b/src/main/java/com/lk/paopao/service/AttachService.java index 4a6e5ca..66fa11f 100644 --- a/src/main/java/com/lk/paopao/service/AttachService.java +++ b/src/main/java/com/lk/paopao/service/AttachService.java @@ -111,41 +111,23 @@ public class AttachService { * @return 文件类型的标识字节,0表示未知类型 */ public static byte getType(String contentType) { - // 存储MIME类型与文件类型标识的映射 - Map map = new HashMap<>(); - // 初始化映射,定义各类文件的类型标识 - map.put("image/jpeg", (byte)1); - map.put("image/png", (byte)1); - map.put("image/gif", (byte)1); - map.put("image/bmp", (byte)1); - map.put("image/webp", (byte)1); - map.put("image/svg+xml", (byte)1); - map.put("image/tiff", (byte)1); - map.put("image/x-icon", (byte)1); - map.put("image/vnd.microsoft.icon", (byte)1); - map.put("video/mp4", (byte)2); - map.put("video/x-msvideo", (byte)2); - map.put("video/x-ms-wmv", (byte)2); - map.put("video/x-flv", (byte)2); - map.put("video/quicktime", (byte)2); - map.put("video/x-matroska", (byte)2); - map.put("video/webm", (byte)2); - map.put("video/ogg", (byte)2); - map.put("application/zip", (byte)3); - map.put("application/x-7z-compressed", (byte)3); - map.put("application/x-rar-compressed", (byte)3); - map.put("application/x-tar", (byte)3); - map.put("application/x-gzip", (byte)3); - map.put("application/x-bzip2", (byte)3); - map.put("application/x-xz", (byte)3); - map.put("application/pdf", (byte)4); - map.put("application/msword", (byte)4); - // 获取文件类型标识 - Byte type = map.get(contentType); - //获取不到type,则返回0 - return type==null?0:type; + if(contentType == null){ + return 0; + } + if(contentType.startsWith("image/")){ + return 1; + } + if(contentType.startsWith("video/")){ + return 2; + } + if(contentType.startsWith("application/")){ + return 3; + } + if(contentType.startsWith("text/")){ + return 4; + } + return 0; } - }