我正在尝试下载大小 > 2 GB 的文件(.tar.gz 格式)。
代码:
try (InputStream fileInputStream = new FileInputStream(file)){
output = response.getOutputStream();
response.setContentType("application/gzip");
response.setContentLength((int) (file.length()));
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
IOUtils.copyLarge(fileInputStream, output);
output.flush();
if(fileInputStream != null) {
fileInputStream.close();
}
}
<小时/>
<小时/>
但出现以下错误。
2019-06-12 14:38:24,840 ERROR [https-jsse-nio-8543-exec-1]-rest.LogBundlesAPI: downloadLogBundle--> Exception occured while reading log bundle in download log bundle REST call.org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
<小时/>
<小时/>
为什么会出现上述错误?还有其他方法可以在 Java 中下载任意大小的文件吗?
最佳答案
使用Chunked transfer encoding 。 大多数 REST 库都支持它(例如 JAX-RS )。我认为你应该考虑使用它。
关于java - Java 中的 Rest API 下载大小 > 3 GB 的文件 (.tar.gz),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56558209/