调整文件下载Content-Type方法位置

This commit is contained in:
wanggeng 2021-09-01 11:55:52 +08:00
parent f3765cadc9
commit 3451de9605

View File

@ -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图片不压缩
*