I follow this approach successfully uploaded to "/var/www/java/Football/src/main/webapp/resources/images" folder but here i need to specify complete path , now question is to get root path directly that is like "webapp/resources/images" no need to specify complete path, how to get root path ?
@RequestMapping(value="/saveDeal",method=RequestMethod.POST)
public String saveDeal(@ModelAttribute("saveDeal") Deal deal,BindingResult result,@RequestParam("couponCode") MultipartFile file,HttpServletRequest request){
if(!file.isEmpty()){
try{
byte[] bytes=file.getBytes();
System.out.println("Byte Data :"+bytes);
String fileName=file.getOriginalFilename();
File newFile = new File("/var/www/java/Football/src/main/webapp/resources/images");
if (!newFile.exists()){
newFile.mkdirs();
}
File serverFile = new File(newFile.getAbsolutePath()+File.separator+fileName);
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
}catch(Exception e){
e.printStackTrace();
}
}
return "redirect:viewDeals.html";
}