Spring
Spring file download (파일 다운로드)
husks
2015. 7. 8. 16:35
반응형
스프링에서 파일 다운로드 하는 예제입니다.
Controller에서 구현하였습니다.
자세한 소스는 http://huskdoll.tistory.com/537 를 참고하세요.^^
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @RequestMapping("/filedown")//URL호출 public void getFile(@RequestParam Map<String,Object> map, HttpServletResponse response) throws Exception { String filePath = (String) map.get("filePath"); //파일 전체경로(파일명도 포함) String oriFileName = (String) map.get("oriFileName"); //파일 원본 경로 String docName = URLEncoder.encode(oriFileName,"UTF-8").replaceAll("\\+", "%20"); //한글파일명 깨지지 않도록 response.setHeader("Content-Disposition", "attachment;filename=" + docName + ";"); response.setContentType("text/plain"); File down_file = new File(filePath); //파일 생성 FileInputStream fileIn = new FileInputStream(down_file); //파일 읽어오기 ByteStreams.copy(fileIn, response.getOutputStream()); response.flushBuffer(); } |
반응형