<FileDownloadController>
@Controller
public class FileDownloadController {
@RequestMapping("/download")
protected void download(@RequestParam("fileName") String fileName,
@RequestParam("goods_id") String goods_id,
HttpServletResponse response, HttpServletRequest request) throws Exception {
OutputStream out = response.getOutputStream();
String CURR_IMAGE_REPO_PATH = request.getSession().getServletContext().getRealPath("/shopImage/shopping/file_repo");
String filePath=CURR_IMAGE_REPO_PATH+"/"+goods_id+"/"+fileName;
File image=new File(filePath);
response.setHeader("Cache-Control","no-cache");
response.addHeader("Content-disposition", "attachment; fileName="+fileName);
FileInputStream in=new FileInputStream(image);
byte[] buffer=new byte[1024*8];
while(true){
int count=in.read(buffer); //���ۿ� �о���� ���ڰ���
if(count==-1) //������ �������� �����ߴ��� üũ
break;
out.write(buffer,0,count);
}
in.close();
out.close();
}
@RequestMapping("/thumbnails.do")
protected void thumbnails(@RequestParam("fileName") String fileName,
@RequestParam("goods_id") String goods_id,
HttpServletResponse response, HttpServletRequest request) throws Exception {
OutputStream out = response.getOutputStream();
String CURR_IMAGE_REPO_PATH = request.getSession().getServletContext().getRealPath("/shopImage/shopping/file_repo");
String filePath=CURR_IMAGE_REPO_PATH+"/"+goods_id+"/"+fileName;
File image=new File(filePath);
int lastIndex = fileName.lastIndexOf(".");
String imageFileName = fileName.substring(0,lastIndex);
if (image.exists()) {
Thumbnails.of(image).size(121,154).outputFormat("png").toOutputStream(out);
}
byte[] buffer = new byte[1024 * 8];
out.write(buffer);
out.close();
}
}
'[자바 클래스&함수] > 코드분석(분석코드 임시저장)' 카테고리의 다른 글
[코드분석] 쿠키, 세션으로 로그인 유지 (0) | 2020.02.04 |
---|---|
[코드분석] 자료실 구축(파일 업로드)(1) (0) | 2020.02.04 |
[코드분석] ViewNameInterceptor (0) | 2020.01.23 |
[코드분석] BaseController (0) | 2020.01.23 |