The question says it. I could not find any information on streaming byte arrays to a postgresql database in spring using r2dbc, e.g. for a file upload.
I can store the bytes, by reading all bytes of a file like this:
@PostMapping("/upload")
suspend fun upload(
@RequestPart("file") filePartMono: Mono<FilePart>
): User {
val filePart = filePartMono.awaitFirstOrNull() ?: throw UploadException("Missing file part")
var inputStream = filePart.content().awaitFirst().asInputStream()
val bytes = coroutineScope {
val bytesDeferred = async(Dispatchers.IO) {
inputStream.readAllBytes()
}
bytesDeferred.await()
}
fileRepository.save(File(bytes));
}
But I would like to stream filePart.content() to the database if possible?