- JAVA
- Spring 프레임워크
- JPA
- React 프레임워크
##드래그 앤 드롭을 지원하는 다중 파일 업로드
- 화면
- 코드
@PostMapping("/pandora")
public String savePandora(@RequestParam("files") List<MultipartFile> files,
@RequestParam("name") String name,
@RequestParam("count") String count,
@RequestParam("code") String code) throws IOException {
String ret="";
int iCount=Integer.parseInt(count);
List<String> fileNames=new ArrayList<>();
try{
for (MultipartFile file : files) {
//DB에 메타데이터를 저장하기 위해 file의 원래 이름을 리스트에 넣어줌
fileNames.add(file.getOriginalFilename());
//실제 저장소에 파일 저장
saveFile(file,directoryPath);
}
//DB에 Pandora 및 file의 메타데이터 저장
Long savedPandoraId = pandoraService.makePandora(name,code, iCount, directoryPath, fileNames);
Pandora newPandora = pandoraService.findOne(savedPandoraId);
ret=newPandora.getKey();
}
catch (IOException e){
System.err.println("IOException occurred!");
}
return ret;
}