diff --git a/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java b/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java index 646ca8c7..ab46bf4f 100644 --- a/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java +++ b/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java @@ -25,6 +25,7 @@ import ink.wgink.util.ResourceUtil; import ink.wgink.util.UUIDUtil; import ink.wgink.util.date.DateUtil; import ink.wgink.util.map.HashMapUtil; +import ink.wgink.util.request.StaticResourceRequestUtil; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.EncoderException; import it.sauronsoftware.jave.MultimediaInfo; @@ -363,7 +364,7 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService ) { boolean isOpen = Boolean.valueOf(params.get("isOpen").toString()); response.setHeader("Content-Length", filePO.getFileSize()); - response.setContentType(getContentType(filePO.getFileType())); + response.setContentType(StaticResourceRequestUtil.getContentType(filePO.getFileType())); if (!isOpen) { response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(filePO.getFileName(), "UTF-8")); } else { @@ -770,74 +771,6 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService return fileMd5; } - /** - * 获取ContentType - * - * @param fileType - * @return - */ - private String getContentType(String fileType) { - String contentType; - switch (fileType) { - case "png": - contentType = "image/png"; - break; - case "blob": - case "jpg": - case "jpeg": - contentType = "image/jpeg"; - break; - case "gif": - contentType = "image/gif"; - break; - case "mp4": - contentType = "video/mp4"; - break; - case "rmvb": - contentType = "application/vnd.rn-realmedia-vbr"; - break; - case "mp3": - contentType = "audio/mp3"; - break; - case "wmv": - contentType = "video/x-ms-wmv"; - break; - case "wav": - contentType = "audio/wav"; - break; - case "doc": - contentType = "application/msword"; - break; - case "docx": - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; - break; - case "xls": - contentType = "application/vnd.ms-excel"; - break; - case "xlsx": - contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - break; - case "ppt": - contentType = "application/vnd.ms-powerpoint"; - break; - case "pptx": - contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; - break; - case "txt": - contentType = "text/plain"; - break; - case "apk": - contentType = "application/vnd.android.package-archive"; - break; - case "pdf": - contentType = "application/pdf"; - break; - default: - contentType = "application/octet-stream"; - } - return contentType; - } - /** * 是否是图片文件, GIF图片不压缩 *