i need to give back an image stored in mogodb with gridfs but every time I get the image, the request remains suspended. In particular, this happens with images over 40k. Actually i use spring data mongodb reactive 2.2.0.M2.
The code used is the following
MediaRepository.kt
fun getById(id: String): Mono<ReactiveGridFsResource> {
return gridFsOperations.findFirst(Query(Criteria.where("_id").`is`(id)))
.flatMap { file ->
gridFsOperations.getResource(file)
}
}
MediaHandler.kt
fun getById(request: ServerRequest): Mono<ServerResponse> {
val id: String = request.pathVariable("id")
return mediaRepository.getById(id)
.flatMap { resource ->
ServerResponse.ok()
.header(CONTENT_TYPE, "image/jpeg")
.body(BodyInserters.fromDataBuffers(resource.downloadStream))
}
.switchIfEmpty(ServerResponse.notFound().build())
}
Thank you in advance