java - Java 中的 Rest API 下载大小 > 3 GB 的文件 (.tar.gz)

标签 java rest

我正在尝试下载大小 > 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/

相关文章:

java - 如何用java从pdf文件中提取结构化信息

java - 我无法在微调器中设置 String[] 值

java - Netbeans 属性表 导航器窗口中容器中的 Swing 控件

flutter - Flutter与FastAPI交互

javax.ws.rs : What is Actually Returned by a Method

java - 使用计划的 cron 时,Spring 计划正常关闭不起作用

java - 为什么测试需要永远执行

c# - 是否可以使用 servicestack 上传文件和发布数据?

php - 尝试通过 paypal 的 REST API (php) 对销售进行退款时的 TRANSACTION_REFUSED

c# - 在xamarin.Android REST服务中获取方法