@Autowired
private HttpServletRequest request;
@RequestMapping(value="upload")
public String upload(@RequestParam("file") MultipartFile file) throws IllegalStateException, IOException{
String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/"
+new Date().getTime() +UUID.randomUUID() +"_"+ file.getOriginalFilename();
file.transferTo(new File(filePath));
return "success.jsp";
}
@RequestMapping(value="download")
public void download(HttpServletRequest request,HttpServletResponse response) throws IOException{
String filename="1.jpg";
response.setContentType("application/x-msdownload");
FileInputStream fis = new FileInputStream(
new File(request.getSession().getServletContext().getRealPath("/upload/")+filename));
response.setHeader("Content-Disposition", "attachment;filename="+filename);
OutputStream os = response.getOutputStream();
IOUtils.copy(fis,os);
}