@GetMapping("/download/{fileName}")
@ResponseBody
public ResponseEntity<Object> downloadFile(@PathVariable(name = "fileName") String fileName) throws FileNotFoundException {
File file = new File(fileUploadRootDir + fileName);
if (!file.exists())
{
return new ResponseEntity<Object>("{\"code\": \"00002\", \"info\":\"File Not Found!\"}", HttpStatus.BAD_REQUEST);
}
InputStreamResource resource = new InputStreamResource( new FileInputStream( file ) );
HttpHeaders headers = new HttpHeaders();
headers.add ( "Content-Disposition",String.format("attachment;filename=\"%s",fileName));
headers.add ( "Cache-Control","no-cache,no-store,must-revalidate" );
headers.add ( "Pragma","no-cache" );
headers.add ( "
springboot 文件下载接口
最新推荐文章于 2025-04-16 13:46:30 发布