mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -2680,23 +2680,24 @@ public class FileUtil extends PathUtil {
|
|||||||
* @since 4.1.15
|
* @since 4.1.15
|
||||||
*/
|
*/
|
||||||
public static String getMimeType(final String filePath) {
|
public static String getMimeType(final String filePath) {
|
||||||
String contentType = URLConnection.getFileNameMap().getContentTypeFor(filePath);
|
if(StrUtil.isBlank(filePath)){
|
||||||
if (null == contentType) {
|
return null;
|
||||||
// 补充一些常用的mimeType
|
|
||||||
if (StrUtil.endWithIgnoreCase(filePath, ".css")) {
|
|
||||||
contentType = "text/css";
|
|
||||||
} else if (StrUtil.endWithIgnoreCase(filePath, ".js")) {
|
|
||||||
contentType = "application/x-javascript";
|
|
||||||
} else if (StrUtil.endWithIgnoreCase(filePath, ".rar")) {
|
|
||||||
contentType = "application/x-rar-compressed";
|
|
||||||
} else if (StrUtil.endWithIgnoreCase(filePath, ".7z")) {
|
|
||||||
contentType = "application/x-7z-compressed";
|
|
||||||
} else if (StrUtil.endWithIgnoreCase(filePath, ".wgt")) {
|
|
||||||
contentType = "application/widget";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 补充
|
// 补充一些常用的mimeType
|
||||||
|
if (StrUtil.endWithIgnoreCase(filePath, ".css")) {
|
||||||
|
return "text/css";
|
||||||
|
} else if (StrUtil.endWithIgnoreCase(filePath, ".js")) {
|
||||||
|
return "application/x-javascript";
|
||||||
|
} else if (StrUtil.endWithIgnoreCase(filePath, ".rar")) {
|
||||||
|
return "application/x-rar-compressed";
|
||||||
|
} else if (StrUtil.endWithIgnoreCase(filePath, ".7z")) {
|
||||||
|
return "application/x-7z-compressed";
|
||||||
|
} else if (StrUtil.endWithIgnoreCase(filePath, ".wgt")) {
|
||||||
|
return "application/widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
String contentType = URLConnection.getFileNameMap().getContentTypeFor(filePath);
|
||||||
if (null == contentType) {
|
if (null == contentType) {
|
||||||
contentType = getMimeType(Paths.get(filePath));
|
contentType = getMimeType(Paths.get(filePath));
|
||||||
}
|
}
|
||||||
|
@@ -431,6 +431,10 @@ public class FileUtilTest {
|
|||||||
// pr#2617@Github
|
// pr#2617@Github
|
||||||
mimeType = FileUtil.getMimeType("test.wgt");
|
mimeType = FileUtil.getMimeType("test.wgt");
|
||||||
Assertions.assertEquals("application/widget", mimeType);
|
Assertions.assertEquals("application/widget", mimeType);
|
||||||
|
|
||||||
|
// issue#3092
|
||||||
|
mimeType = FileUtil.getMimeType("https://xxx.oss-cn-hangzhou.aliyuncs.com/xxx.webp");
|
||||||
|
Assertions.assertEquals("image/webp", mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user