@RequestMapping("download.do")
public void download(HttpServletResponse response, @RequestParam("id")String id) throws Exception {
// id를 이용해 db에서 파일 fullPath 와 ofn 얻어오기
String ofn = service.getOfn(id);
String fullPath = service.getFilePath(id);
File target = new File(fullPath);
byte[] b = new byte[1024 * 1024 * 10];
DataOutputStream dos = new DataOutputStream(new FileOutputStream(target));

response.reset();
response.setContentType("application/octet-stream");

String fileName = new String(ofn.getBytes("utf8"), "8859_1");
response.setHeader("Content-Disposition", "attatchment; filename = " + fileName);
response.setHeader("Content-length", String.valueOf((int)target.length()));

FileInputStream fis = new FileInputStream(target);
ServletOutputStream sos = response.getOutputStream();

int num;
while((num = fis.read(b,0,b.length)) != -1) {
sos.write(b,0,num);
}
sos.flush();
sos.close();
fis.close();



}

+ Recent posts