Using Spring MVC Upload image to /webapp/resources/images directory -


i follow approach uploaded "/var/www/java/football/src/main/webapp/resources/images" folder here need specify complete path , question root path directly "webapp/resources/images" no need specify complete path, how 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"; } 

this works fine try out....it return entire path

string filepath = "/uploads/filename";      // absolute path of application     servletcontext context = request.getservletcontext();     string apppath = context.getrealpath(""); 

or

string filepath = "/uploads/" + "tenant/" + tenant + "/project/"                 + projectid + "/task/" + taskid;         string realpathtofetch = request.getservletcontext().getrealpath(                 filepath); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -