Java 从外部http资源流式传输内容

Java 从外部http资源流式传输内容,java,spring-boot,resttemplate,Java,Spring Boot,Resttemplate,我试图使用spring boot应用程序作为外部托管的某些图像或视频内容的代理 @GetMapping("/video.mp4") public ResponseEntity<Resource> getVideo(@PathVariable String filename) { HttpHeaders headers = getHttpHeaders(filename); ResponseEntity<Resource> exchange = restTe

我试图使用spring boot应用程序作为外部托管的某些图像或视频内容的代理

@GetMapping("/video.mp4")
public ResponseEntity<Resource> getVideo(@PathVariable String filename) {
    HttpHeaders headers = getHttpHeaders(filename);
    ResponseEntity<Resource> exchange = restTemplate.exchange("https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_30mb.mp4", HttpMethod.GET, entity, Resource.class);

    return ResponseEntity.ok().headers(headers).body(exchange.getBody());
}
@GetMapping(“/video.mp4”)
公共响应属性getVideo(@PathVariable字符串文件名){
HttpHeaders=getHttpHeaders(文件名);
ResponseEntity exchange=restTemplate.exchange(“https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_30mb.mp4,HttpMethod.GET,实体,资源.class);
返回ResponseEntity.ok().headers(headers).body(exchange.getBody());
}
我想将内容从外部资源流式传输到客户端,而不首先下载它。我上面的示例代码似乎首先将完整内容下载到内存中,然后提供服务


如何在不先下载的情况下直接代理内容?

为什么要使用
restemplate
?1) 它是一个视频文件而不是REST端点2)默认情况下,它将“下载”视频(因为它就是这样做的)。要将其流式传输到客户端,需要首先从源中流式传输if。一旦你同意了,你就需要创建一个从浏览器客户端到你的SB应用程序的流式连接-祝你好运。如果源服务器没有将其作为流式响应发送,那么我想你必须完全下载它。但一旦你们在某个地方有了那个文件,你们就可以从文件中读取它并将其作为StreamingResponseBody返回。