Apache tomcat spring mvc webapp file upload

2

I am creating an application with Spring MVC, in which users upload files, I understand that the files can not be located within the project since this would make my .WAR file very heavy and these files would be lost if I re-deploy the application .

My question is:

In what place do you explicitly place them without lose when redeploying the application? they can be located within tomcat? or I need another tool.

    
asked by Angelica Luna 02.03.2017 в 06:41
source

1 answer

2

You can locate the files in the server path you want, you could do something in the controller, assuming you have a file called file :

String uploadsDir = "<RUTA>";

if(! new File(uploadsDir).exists())
    new File(uploadsDir).mkdir();

String filePath = uploadsDir + "\" + file.getOriginalFilename();

File dest = new File(filePath);

file.transferTo(dest);
    
answered by 25.04.2017 в 09:53