下面的代码总是下载一个 f.txt
文件,而不是在没有实际文件名和扩展名(这里是 .zip 扩展名)的情况下下载。
@RequestMapping(value = "/files/{fileId}", method = RequestMethod.GET, produces = "application/zip")
public ResponseEntity<Resource> downloadFile(@PathVariable("fileId") String fileName) {
log.info("Downloading file..!!!!");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.valueOf("application/zip"));
log.info("Content info : "+headers.getContentType().toString());
File file = FileUtils.getFile("backup/" + fileName + ".zip");
log.info("File name is : "+file.getName());
FileSystemResource fileSystemResource = new FileSystemResource(file);
return new ResponseEntity<>(fileSystemResource, headers, HttpStatus.OK);
}
如果有人能告诉我错误在哪里/需要做一些修改,那就太好了?
最佳答案
f.txt
来自 Content-Disposition
响应 header 。这是修复 cve-2015-5211 的结果(RFD 攻击)
关于java - .zip 文件下载为 f.txt 文件 - spring boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41364732/