我用如下代码,可以下载文件,但是无法在后端准确统计下载时间
public ResponseEntity<Resource> downloadFixedFile(String userid,String sliceName,HttpServletRequest request) {
// 创建文件对象
File file = new File(filePath);
// 判断文件是否存在
if (!file.exists()) {
//throw new FileNotFoundException("File not found: ");// + fileName
return ResponseEntity.notFound().build();
}
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Length", String.valueOf(fileSize));
headers.add("Content-Disposition", "attachment; filename=" +文件名);
// 创建文件资源对象
Resource resource = new FileSystemResource(file);
// 返回整个文件内容
ResponseEntity<Resource> responseEntity = ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new InputStreamResource(resource.getInputStream()));
long endTime1 = System.currentTimeMillis();
long duration = endTime1 - startTime;
System.out.println("allocateModelslices,下载文件,程序耗时:" + duration + " 毫秒");
System.out.println(打印当前时间_精确到毫秒.打印时间到毫秒() + " " + sliceName + " 下载文件结束");
// 返回整个文件内容
return responseEntity;
springboot项目,返回 ResponseEntity 对象的话,就无法在后端准确统计下载时间。请问这样的代码,如何修改,才能在后端准确统计下载时间?谢谢