解决办法:
URL path = new URL(url);
HttpURLConnection connection = (HttpURLConnection) path.openConnection();
// 获取文件总长度
long contentLength = connection.getContentLengthLong();
// 设置Content-Length响应头部
response.setHeader("Content-Length", String.valueOf(contentLength));