Skip to content

Commit

Permalink
fix: upload attachment issue (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao committed Oct 19, 2023
1 parent e0e8c04 commit e2c7cf2
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Mono<Attachment> upload(AttachmentUploadCondition uploadCondition) {

// upload file data buffer
return writeDataToFsPath(uploadCondition.getDataBufferFlux(), Path.of(uploadFilePath))
.publishOn(Schedulers.boundedElastic())
//.publishOn(Schedulers.boundedElastic())
.flatMap(fsPath ->
// rename if isAutoReName=true and exists same file.
repository.existsByTypeAndParentIdAndName(
Expand Down Expand Up @@ -334,12 +334,26 @@ public Mono<Void> receiveAndHandleFragmentUploadChunkFile(String unique,
}
tempChunkFileCacheDir.delete();

File file = new File(filePath);
Flux<DataBuffer> dataBufferFlux = FileUtils.convertToDataBufferFlux(file);

return upload(AttachmentUploadCondition.builder()
.name(uploadName).dataBufferFlux(dataBufferFlux).parentId(parentId)
.build()).then();
Long finalParentId = parentId;
return
// rename if exists same file.
repository.existsByTypeAndParentIdAndName(
AttachmentType.File, parentId, uploadName
)
.filter(exists -> exists)
.map(exists -> System.currentTimeMillis() + "-" + uploadName)
.switchIfEmpty(Mono.just(uploadName))
.flatMap(n ->
// save attachment entity
saveEntity(AttachmentEntity.builder()
.parentId(finalParentId)
.fsPath(filePath)
.updateTime(LocalDateTime.now())
.type(AttachmentType.File)
.name(n)
.url(path2url(filePath, ikarosProperties.getWorkDir().toString()))
.size(findFileSize(filePath))
.build())).then();
}
return Mono.empty();
}
Expand Down

0 comments on commit e2c7cf2

Please sign in to comment.