我正在尝试创建可以下载大文件(20Gb或更多)的文件。
我休息了
export const list: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
cb(null, response);
}
我在其中设置标题,所有必需的信息等。 为什么我使用BufferedStreams,因为我也尝试使用not BufferedStreams 但这仍然没有帮助我。
我尝试每2 MB刷新一次,但仍然失败。
我得到的异常是:
@GetMapping(value = "/auth/downloadFileFromServer/{encodedName:.+}")
public void getFile(@PathVariable String encodedName, HttpServletResponse response, HttpServletRequest request) throws IOException, InterruptedException {
Resource resource = torrentFileService.loadFileAsResource(Long.valueOf(encodedName));
response.setContentType(request.getServletContext().getMimeType(resource.getFile().getAbsolutePath()));
response.setContentLengthLong(resource.getFile().length());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"");
BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(resource.getFile()));
BufferedOutputStream outStream = new BufferedOutputStream(response.getOutputStream());
int bytesRead;
byte[] bytes = new byte[1024 * 8];
while ((bytesRead = inStream.read(bytes)) != -1) {
outStream.write(bytes, 0, bytesRead);
}
outStream.flush();
inStream.close();
}
我还做了些什么,我尝试更改虚拟机内存设置,就像here中所说的那样 我尝试过的另一个solution
矿主文件具有下一个批注@SpringBootApplication(scanBasePackages =“ com.google”,排除= ErrorMvcAutoConfiguration.class)