如何使用spring webflux进行文件流传输

时间:2017-08-06 12:55:05

标签: spring-webflux

我想使用spring webflux以反应方式流式传输文件 我的端点应该如何更具体地说明对象的类型是什么?

@GetMapping("/file")
Flux<???> file() {
    //Read file content into this ??? thing . 
}

1 个答案:

答案 0 :(得分:2)

您可以像这样返回Resource个实例:

@GetMapping("/file")
Mono<Resource> file() {
    //Create a ClassPathResource, for example
}

请注意,这会自动支持字节范围HTTP请求。