티스토리 뷰

스프링 프레임워크 환경에서 파일 업로드 시 대략적인 흐름을 작성했습니다.

세부 사항은 추가하면서 작성하면 되겠습니다.

public Map<String, Object> fileUpload(HttpServletRequest request) throws Exception{


    Map<String, Object> resultMap = new HashMap<String, Object>();

    DateFormat dfFormat = new SimpleDateFormat("yyyyMMdd");

    Date nowDate = new Date();

    String toDate = format.dfFormat(nowDate);

    String filePath = toDate+"/";

    String fullPath=rootPath+filePath;

    File file = new File(fullPath);

    if(!file.isDirectory){

        file.mkdirs();

    }


    MultipartHttpServletRequest multipart = null;

    Enumeration enuParamName = null;

    if(request.getContentType() != null && request.getContentType().indexOf("multipart/form-data") > -1){

        multipart = (MultipartHttpServletRequest)request;

        List<multipartFile> files = multipart.getFiles("");

        //파라미터사용시

        enuParamName = multipart.getParamterNames();

        for(int j=0; j < files.size; j++){

            multipartFile = files.get(j);

            file = new File(pathFile);

            multipartFile.transferTo(file);

            paramMap.put("fileNo", fileNo);

        }

    }

}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함