Files (pictures, excel tables, etc.) files uploaded to the server save, then get a save path, you can download the file (download path can be achieved according to the front) according to this path.
Specific code as follows:
@PostMapping ( "/ Upload" ) public void uploadPhoto (@RequestParam ( "the uploadFile") a MultipartFile the uploadFile, @RequestParam ( "aiIdCard" ) String aiIdCard, the HttpServletRequest Request) { // path defined upload stored String path = request.getSession . () .getServletContext () getRealPath ( "/ uploadFile /" ); System.out.println (path); // definition file in the file upload path folder name file folder = new new file (path + aiIdCard); // detecting whether the folder is a folder that is not created iF (! folder.isDirectory ()) { folder.mkdirs (); } // get the original name of the file OldName = String uploadFile.getOriginalFilename (); // get the file of oldName.substring ( "." OldName.lastIndexOf () ) suffix // generate a new file name (below according to their own needs to decide whether to use) // String = newName oldName.substring (oldName.lastIndexOf () "."); // file save operation uploadFile.transferTo ( new new file (Folder, oldName)); // returns save the url, you can view or download files according to url String filePath = request.getScheme () + ": //" + to request.getServerName () + ":" + to request.getServerPort () + "/ the uploadFile /" + + aiIdCard in oldName;
}