Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upload attachment issue #480

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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