Java – download stream files through resttemplate

I have a large file download, which is provided by the restcontroller on one server. I need to stream it through the restcontroller on another server When calling the terminal server directly, the result flow is very good However, when this server is called using resttemplate and the response is written to OutputStream, the response is buffered on the front-end server until the entire file is ready for streaming Is there any way to write files to OutputStream?

At present, my code on the front-end server looks similar

@ResponseBody
public void downloadResults(HttpServletRequest request,HttpServletResponse response,@RequestParam("id") String jobId,OutputStream stream)
        throws IOException
{
    byte[] data = restTemplate.exchange("http://localhost/getFile",HttpMethod.POST,requestEntity,byte[].class,parameters).getBody();
    stream.write(data);
}

I have set resttemplate to not buffer, and I have verified that this is valid by checking the type of request used (simplestreamingclienthttprequest) All the data is correct. It only writes to the stream at a time, not its contents

Solution

Resttemplate is not a response body for streaming transmission, such as pointed out in this JIRA issue

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>