Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store user uploads in spring mvc application?

I am wondering where should i save files uploaded by user in my application. Right now i am saving them right into webapps/images/uploads(webapps folder is mapped as resource folder via mvc-resource) folder and they are instantly available to display after upload. But i am not sure if this is the right thing to do? how will redeployment of application affect the files already stored there? won't it complicate back ups of application? so basically where should i store them on server? and is this affected somehow by using local(windows) or remote(linux) server Thanks

like image 575
Schyzotrop Avatar asked Jan 02 '11 14:01

Schyzotrop


People also ask

How would you handle the situation where a user uploads a very large file through a form in your Spring MVC application?

A new attribute "maxSwallowSize" is the key to deal this situation. It should happen when you upload a file which is larger than 2M. Because the 2M is the default value of this new attribute .

Which dependency is needed to support uploading of a file in MVC?

The dependency needed for MVC is the spring-webmvc package. The javax. validation and the hibernate-validator packages will be also used here for validation. The commons-io and commons-fileupload packages are used for uploading the file.

How do I upload files to Spring boot?

Spring Boot file uploader Create a Spring @Controller class; Add a method to the controller class which takes Spring's MultipartFile as an argument; Save the uploaded file to a directory on the server; and. Send a response code to the client indicating the Spring file upload was successful.


1 Answers

I will use a separate directory outside the webapp directory of the application server. In case of update of the application, this seems more appropriate. Just be careful how you save the file name in the database (it's better to save the file without any path, in case of changes).

like image 65
Kartoch Avatar answered Oct 08 '22 11:10

Kartoch