diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FilePageReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FilePageReqVO.java
index 043cf11bb..e803fcf25 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FilePageReqVO.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FilePageReqVO.java
@@ -21,8 +21,8 @@ public class FilePageReqVO extends PageParam {
@ApiModelProperty(value = "文件路径", example = "yudao", notes = "模糊匹配")
private String path;
- @ApiModelProperty(value = "文件扩展名", example = "jpg", notes = "模糊匹配")
- private String extName;
+ @ApiModelProperty(value = "文件类型", example = "application/octet-stream", notes = "模糊匹配")
+ private String type;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java
index 7a53bf2e1..fa6ec8444 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java
@@ -22,11 +22,8 @@ public class FileRespVO {
@ApiModelProperty(value = "文件 URL", required = true, example = "https://www.iocoder.cn/yudao.jpg")
private String url;
- @ApiModelProperty(value = "文件扩展名", example = "jpg")
- private String extName;
-
@ApiModelProperty(value = "文件MIME类型", example = "application/octet-stream")
- private String mimeType;
+ private String type;
@ApiModelProperty(value = "文件大小", example = "2048", required = true)
private Integer size;
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
index 36ef56113..ae898c8cd 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
@@ -45,16 +45,11 @@ public class FileDO extends BaseDO {
* 访问地址
*/
private String url;
- /**
- * 文件扩展名
- *
- * 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取
- */
- private String extName;
+
/**
* 文件的MIME类型,默认为"application/octet-stream"
*/
- private String mimeType;
+ private String type;
/**
* 文件大小
*/
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java
index 28c37067c..845addc14 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java
@@ -18,7 +18,7 @@ public interface FileMapper extends BaseMapperX {
default PageResult selectPage(FilePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX()
.likeIfPresent(FileDO::getPath, reqVO.getPath())
- .likeIfPresent(FileDO::getExtName, reqVO.getExtName())
+ .likeIfPresent(FileDO::getType, reqVO.getType())
.betweenIfPresent(FileDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(FileDO::getId));
}
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
index cf6dc700b..0df38d22c 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
@@ -41,12 +41,12 @@ public class FileServiceImpl implements FileService {
@Override
@SneakyThrows
public String createFile(String name, String path, String mimeType, byte[] content) {
- //获取文件的真实扩展名
- String extName = FileTypeUtil.getType(new ByteArrayInputStream(content), name);
- FileNameUtil.extName(name);
+ //获取文件的扩展名
+ String extName = FileNameUtil.extName(name);
if (StrUtil.isEmpty(path)) {
//使用sha256计算文件都唯一路径,降低碰撞概率
- path = DigestUtil.sha256Hex(content) + '.' + extName;
+ String sha256Hex = DigestUtil.sha256Hex(content);
+ path = StrUtil.isBlank(extName) ? sha256Hex : (sha256Hex + '.' + extName);
}
// 如果 name 为空,则使用 path 填充
if (StrUtil.isEmpty(name)) {
@@ -64,8 +64,7 @@ public class FileServiceImpl implements FileService {
file.setName(name);
file.setPath(path);
file.setUrl(url);
- file.setExtName(extName);
- file.setMimeType(mimeType);
+ file.setType(mimeType);
file.setSize(content.length);
fileMapper.insert(file);
return url;
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
index 21db8ac8a..a4e9966a5 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
@@ -40,16 +40,11 @@ public class FileServiceTest extends BaseDbUnitTest {
// mock 数据
FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到
o.setPath("yunai");
- o.setExtName("jpg");
o.setCreateTime(buildTime(2021, 1, 15));
});
fileMapper.insert(dbFile);
// 测试 path 不匹配
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou")));
- // 测试 type 不匹配
- fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
- o.setExtName("png");
- }));
// 测试 createTime 不匹配
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
o.setCreateTime(buildTime(2020, 1, 15));
@@ -90,7 +85,6 @@ public class FileServiceTest extends BaseDbUnitTest {
assertEquals(10L, file.getConfigId());
assertEquals(path, file.getPath());
assertEquals(url, file.getUrl());
- assertEquals("jpg", file.getExtName());
assertEquals(content.length, file.getSize());
}
diff --git a/yudao-ui-admin/src/views/infra/file/index.vue b/yudao-ui-admin/src/views/infra/file/index.vue
index 76e189c83..5bcf721a3 100644
--- a/yudao-ui-admin/src/views/infra/file/index.vue
+++ b/yudao-ui-admin/src/views/infra/file/index.vue
@@ -30,11 +30,10 @@
-
-
+
-
+
@@ -101,8 +100,7 @@ export default {
queryParams: {
pageNo: 1,
pageSize: 10,
- path: null,
- extName: null,
+ path: null
},
// 用户导入参数
upload: {