将文件发送给用户作为响应后,如何自动删除文件?
我正在使用Spring MVC 5
@GetMapping("/download")
public ResponseEntity<InputStreamResource> download(@RequestParam String fileName) throws FileNotFoundException {
File tempLocation = new File("tmp/" + fileName);
myservice.downloadObject(fileName, tempLocation);
InputStreamResource resource = new InputStreamResource(new FileInputStream(downloaded));
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + downloaded.getName())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(downloaded.length())
.body(resource);
}