下载代码
@RequestMapping(value="/download",method=RequestMethod.GET)
public ResponseEntity<byte[]> download(HttpServletRequest request, @RequestParam("filename") String filename,
Model model) throws IOException{
String downloadFilePath="D:\\upload";
File file = new File(downloadFilePath+File.separator+filename);
HttpHeaders headers = new HttpHeaders();//http头信息
String downloadFileName = new String(filename.getBytes("UTF-8"),"iso-8859-1");//设置编码
//设置附件名字
headers.setContentDispositionFormData("attachment", downloadFileName);
//设置传输数据类型
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED); |
|