From 4fcf2042b20a599728f9f63d10a6f1589232890b Mon Sep 17 00:00:00 2001 From: whz <303054730@qq.com> Date: Wed, 22 May 2024 14:16:51 +0800 Subject: [PATCH] fix --- docs/tasks/任务9-Sprint-2- 文件上传.md | 49 +++++++++----------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/docs/tasks/任务9-Sprint-2- 文件上传.md b/docs/tasks/任务9-Sprint-2- 文件上传.md index 4ebe6d6..c45d2c2 100644 --- a/docs/tasks/任务9-Sprint-2- 文件上传.md +++ b/docs/tasks/任务9-Sprint-2- 文件上传.md @@ -306,40 +306,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; } } ```