I have controller method that receives and uploaded file from a web form. How can I extract the byte array out of the FilePart and save it to DB?
I can do it by saving the FilePart to a file using FilePart.transferTo() but that seems slow and ugly. Any nicer way of doing it?
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.*;
Mono<UploadResult> uploadFile(@RequestParam("files") FilePart file){
byte[] fileAsByteArray = convertFilePartToByteArray(file);
fileService.saveByteArrayToDB(fileAsByteArray);
/* Rest of the method */
}