본문 바로가기

푸로그래밍/SPRING, JSP

java.io.File을 MutlipartFile로 변환

반응형
File file = new File("/path/to/file");
FileItem fileItem = new DiskFileItem("mainFile", Files.probeContentType(file.toPath()), false, file.getName(), (int) file.length(), file.getParentFile());

IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());

MultipartFile multipartFile = new CommonsMultipartFile(fileItem);

 

 

 

반응형