Closed ion1ze closed 4 months ago
用的哪个版本
用的哪个版本 jdk:17 springboot:3.2.4 x-file-storage:2.2.0
好的,感谢你的反馈,我这边看一下
我这边测试没问题,能否提供更多配置文件及复现代码?
配置文件:
dromara:
x-file-storage:
default-platform: local-plus
local-plus:
- platform: local-plus
enable-storage: true
enable-access: true
domain: http://localhost:8080/uploads/
path-patterns: /uploads/**
storage-path: ${user.dir}/.data/uploads/
FileRecord 实现类:
@Slf4j
@Service
@RequiredArgsConstructor
public class InfraFileServiceImpl extends ServiceImpl<InfraFileMapper, InfraFile> implements InfraFileService {
public InfraFile toInfraFile(FileInfo source) throws JsonProcessingException {
InfraFile target = new InfraFile();
target.setUrl(source.getUrl());
target.setSize(source.getSize());
target.setFilename(source.getFilename());
target.setType(source.getContentType());
target.setOriginalFilename(source.getOriginalFilename());
target.setBasePath(source.getBasePath());
target.setPath(source.getPath());
target.setExtension(source.getExt());
target.setPlatform(source.getPlatform());
target.setChecksum(JsonUtil.toJsonString(source.getHashInfo()));
target.setObjectId(source.getObjectId());
target.setObjectType(source.getObjectType());
target.setMetadata(JsonUtil.toJsonString(source.getMetadata()));
target.setUserMetadata(JsonUtil.toJsonString(source.getUserMetadata()));
target.setAcl(JsonUtil.toJsonString(source.getFileAcl()));
target.setAttributes(JsonUtil.toJsonString(source.getAttr()));
// 缩略图
target.setThumbnailUrl(source.getThUrl());
target.setThumbnailSize(source.getThSize());
target.setThumbnailFilename(source.getFilename());
target.setThumbnailType(source.getThContentType());
target.setThumbnailMetadata(JsonUtil.toJsonString(source.getThMetadata()));
target.setThumbnailUserMetadata(JsonUtil.toJsonString(source.getThUserMetadata()));
target.setThumbnailAcl(JsonUtil.toJsonString(source.getThFileAcl()));
// 分片
target.setUploadId(source.getUploadId());
target.setUploadStatus(source.getUploadStatus());
return target;
}
public FileInfo toFileInfo(InfraFile source) throws JsonProcessingException {
FileInfo target = new FileInfo();
target.setUrl(source.getUrl());
target.setSize(source.getSize());
target.setFilename(source.getFilename());
target.setContentType(source.getType());
target.setOriginalFilename(source.getOriginalFilename());
target.setBasePath(source.getBasePath());
target.setPath(source.getPath());
target.setExt(source.getExtension());
target.setPlatform(source.getPlatform());
target.setHashInfo(JsonUtil.parseObject(source.getChecksum(), HashInfo.class));
target.setObjectId(source.getObjectId());
target.setObjectType(source.getObjectType());
target.setMetadata(JsonUtil.parseObjectMap(source.getMetadata(), String.class, String.class));
target.setUserMetadata(JsonUtil.parseObjectMap(source.getUserMetadata(), String.class, String.class));
target.setAttr(JsonUtil.parseObject(source.getAttributes(), Dict.class));
// 缩略图
target.setThUrl(source.getThumbnailUrl());
target.setThSize(source.getThumbnailSize());
target.setThFilename(source.getThumbnailFilename());
target.setThContentType(source.getThumbnailType());
target.setThMetadata(JsonUtil.parseObjectMap(source.getThumbnailMetadata(), String.class, String.class));
target.setThUserMetadata(JsonUtil.parseObjectMap(source.getThumbnailUserMetadata(), String.class, String.class));
// 分片
target.setUploadId(source.getUploadId());
target.setUploadStatus(source.getUploadStatus());
return target;
}
@Override
@SneakyThrows
public boolean save(FileInfo fileInfo) {
InfraFile entity = toInfraFile(fileInfo);
boolean result = this.save(entity);
if (result) {
fileInfo.setId(String.valueOf(entity.getId()));
}
return result;
}
@Override
@SneakyThrows
public void update(FileInfo fileInfo) {
InfraFile entity = toInfraFile(fileInfo);
super.updateById(entity);
}
@Override
public FileInfo getByUrl(String url) {
LambdaQueryWrapper<InfraFile> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InfraFile::getUrl, url);
return Optional.ofNullable(super.getOne(queryWrapper))
.map(source -> {
try {
return toFileInfo(source);
} catch (JsonProcessingException e) {
log.error("JsonProcessingException", e);
return null;
}
}).orElse(null);
}
@Override
public boolean delete(String url) {
LambdaQueryWrapper<InfraFile> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InfraFile::getUrl, url);
return super.remove(queryWrapper);
}
@Override
public void saveFilePart(FilePartInfo filePartInfo) {
}
@Override
public void deleteFilePartByUploadId(String s) {
}
@Override
public PaginationResponse<InfraFileDetailsResponse> pagination(InfraFilePaginationRequest request) {
LambdaQueryWrapper<InfraFile> queryWrapper = new LambdaQueryWrapper<>();
Page<InfraFile> page = super.page(Page.of(request.getPageNumber(), request.getPageSize()), queryWrapper);
List<InfraFileDetailsResponse> records = page.getRecords().stream()
.map(InfraFileDetailsResponse::from)
.toList();
return PaginationResponse.of(page.getCurrent(), page.getSize(), page.getTotal(), records);
}
}
依赖版本:
<hutool.version>5.8.26</hutool.version>
<guava.version>33.2.0-jre</guava.version>
<sa-token.version>1.37.0</sa-token.version>
<transmittable-thread-local.version>2.14.5</transmittable-thread-local.version>
<springdoc.version>2.3.0</springdoc.version>
<caffeine.version>3.1.8</caffeine.version>
<x-file-storage.version>2.2.0</x-file-storage.version>
<retrofit2.version>2.9.0</retrofit2.version>
<okhttp3.version>4.9.3</okhttp3.version>
<!--<flyway.version>7.15.0</flyway.version>-->
<mybatis-plus.version>3.5.5</mybatis-plus.version>
<mybatis-plus-join.version>1.4.9</mybatis-plus-join.version>
<mysql.version>8.2.0</mysql.version>
<zxing.version>3.5.3</zxing.version>
<java.version>17</java.version>
加个QQ群 515706495 咱们详细讨论一下
原因是 MultipartFile 支持移动文件功能,在本地存储平台下会不读取输入流,就导致没有计算hash出现此问题。 目前dev分支已修复此问题并发布了快照版本 2.2.1-SNAPSHOT 可以使用,也可以使用下面的上传方式来避免此问题
FileInfo fileInfo = this.fileStorageService.of(file.getInputStream(), file.getName(), file.getContentType(), file.getSize())
.setHashCalculatorMd5()
.upload();
调用方式如下:
上传了几个不同的文件