REST 응용 프로그램을 구축 중입니다. 파일을 업로드하고 싶습니다. 예를 들어/WEB-INF/resource/uploads에 저장하고 싶습니다.REST 응용 프로그램에서 HttpRequest없이 파일 업로드를위한 컨텍스트 경로
어떻게이 디렉토리의 경로를 얻을 수 있습니까? 내 컨트롤러는 다음과 같습니다.
@RequestMapping(value = "/admin/house/update", method = RequestMethod.POST)
public String updateHouse(House house, @RequestParam("file") MultipartFile file, Model model) {
try {
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (file.getSize() > 0) {
inputStream = file.getInputStream();
fileName = "D:/" + file.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
}
} catch(Exception ex) {
ex.printStackTrace();
}
model.addAttribute("step", 3);
this.houseDao.update(house);
return "houseAdmin";
}
두 번째 질문 ... 사용자 파일을 업로드하는 가장 좋은 장소는 무엇입니까?
위대한입니다. 훨씬 더 짧고, 훨씬 간단하고, 훨씬 좋습니다 :) 감사합니다. – Fixus