2

I need to response with image jpeg data

@Controller
@RequestMapping("/resource")
class ResourceController() {

    @GetMapping("/thumbnail/{userFileId}/{group}/{index}", produces = [MediaType.IMAGE_JPEG_VALUE])
    suspend fun getThumbnail(
        @PathVariable userFileId: String,
        @PathVariable group: String,
        @PathVariable index: Int,
        response: ServerHttpResponse
    ) {
        val url = service.getThumbnailUrl(userFileId, group, index)
            ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)

        response.headers.contentType = MediaType.IMAGE_JPEG
        response.statusCode = HttpStatus.OK
        streamResponse(url, response)
    }
}

    @Throws(ResponseStatusException::class)
    private fun streamResponse(url: String, response: ServerHttpResponse) {
        ....
        response.headers.contentLength = contentLength
        content.use { content -> 
            response.writeWith(
                DataBufferUtils.readInputStream({ content }, response.bufferFactory(), 128)
            ).subscribe()
        }
    }

It works, but error in console:

Could not resolve view with name 'resource/thumbnail/xxx/common/2'

Same approach works with spring-boot-starter-web.

Unfortunately I can't find the documentation how to use spring boot + kotlin + webflux

Hett
  • 3,484
  • 2
  • 34
  • 51

0 Answers0