Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Mono<Void> deleteImage(String fileId) {
- return Mono.fromRunnable(() -> {
- imageRepository.findById(fileId)
- .map(image -> {
- Mono<Void> deleteFile = Mono.fromRunnable(() -> {
- try {
- Files.deleteIfExists(Paths.get(UPLOAD_ROOT, image.getId() + "-" + image.getName()));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- });
- Mono<Void> deleteRecord = Mono.fromRunnable(() -> {
- imageRepository.delete(image);
- });
- return Mono.when(deleteFile, deleteRecord).then();
- });
- }).then();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement