Home > other >  Upload pictures always to target directory rather than their directory under the web - app, how to d
Upload pictures always to target directory rather than their directory under the web - app, how to d

Time:09-26




Controller:

//upload pictures
@ RequestMapping (" uploadPic/. Do ")
Public void uploadPic (it request,
@ RequestParam (required=false) MultipartFile PIC) throws IOException {

//upload file path
String path=request. GetSession (). GetServletContext () getRealPath ("/upload/");
//upload file name
The String fileName=PIC. GetOriginalFilename ();
The File filePath=new File (the path and fileName);
//determine whether path exists, if there is no will create a
if(! FilePath. GetParentFile (). The exists ()) {
FilePath. GetParentFile (). The mkdir ();
}
//will upload the file to a target file
PIC. TransferTo (new File (path + File. The separator + fileName));


}

Project:



How to upload the picture path changes for the upload under the webapp directory? Thank you sincerely,



CodePudding user response:

To ask? The building Lord solved
  • Related