I am trying to upload file to SpringBoot webflux controller. The controller must save the file and record the file informations (filesize, name, user, and path) in the db.
@PostMapping(value="upload/single", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Mono<Void> uploadSingle(Authentication auth, @RequestPart("file") Mono<FilePart> filePartMono)
{
String filePath = fileAssetService.baseFilePath();
filePartMono.doOnNext(filePart -> System.out.println(filePart.filename()))
.flatMap(filePart -> filePart.transferTo(new File(filePath+filePart.filename())));
filePartMono.doOnNext(filePart -> fileAssetService.processReceiveFile(new File(filePath+filePart.filename()), auth.getName())).then();
return ress;
}
The above code works only either saving or writing db. Not one after another in sequence.
After the flatMap(filePart -> filePart.transferTo(new File(filePath+filePart.filename()))); I get the Void. So, I could not access the file size. Please advise how to get the size of the file after save.
Thanks, in advance.