修改mimetype字段为type,修改获取文件后缀名方式,目前图片文件预览还有些问题
This commit is contained in:
parent
0ed3321719
commit
da0ba10503
@ -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 = "开始创建时间")
|
||||
|
@ -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;
|
||||
|
@ -45,16 +45,11 @@ public class FileDO extends BaseDO {
|
||||
* 访问地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 文件扩展名
|
||||
* <p>
|
||||
* 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取
|
||||
*/
|
||||
private String extName;
|
||||
|
||||
/**
|
||||
* 文件的MIME类型,默认为"application/octet-stream"
|
||||
*/
|
||||
private String mimeType;
|
||||
private String type;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
|
@ -18,7 +18,7 @@ public interface FileMapper extends BaseMapperX<FileDO> {
|
||||
default PageResult<FileDO> selectPage(FilePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<FileDO>()
|
||||
.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));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,10 @@
|
||||
<el-table-column :show-overflow-tooltip="true" label="文件路径" align="center" min-width="300" prop="path" />
|
||||
<el-table-column :show-overflow-tooltip="true" label="文件 URL" align="center" min-width="400" prop="url" />
|
||||
<el-table-column label="文件大小" align="center" prop="size" width="120" :formatter="sizeFormat" />
|
||||
<el-table-column label="文件类型" align="center" prop="mimeType" width="210" />
|
||||
<el-table-column label="文件扩展名" align="center" prop="extName" width="80" />
|
||||
<el-table-column label="文件类型" align="center" prop="type" width="210" />
|
||||
<!-- <el-table-column label="文件内容" align="center" prop="content">-->
|
||||
<!-- <template slot-scope="scope">-->
|
||||
<!-- <img v-if="scope.row.extName === 'jpg' || scope.row.extName === 'png' || scope.row.extName === 'gif'"-->
|
||||
<!-- <img v-if="scope.row.type&&scope.row.type.indexOf('image/') === 0"-->
|
||||
<!-- width="200px" :src="getFileUrl + scope.row.id">-->
|
||||
<!-- <i v-else>非图片,无法预览</i>-->
|
||||
<!-- </template>-->
|
||||
@ -101,8 +100,7 @@ export default {
|
||||
queryParams: {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
path: null,
|
||||
extName: null,
|
||||
path: null
|
||||
},
|
||||
// 用户导入参数
|
||||
upload: {
|
||||
|
Loading…
Reference in New Issue
Block a user