I need to upload files to server and that part I have successfully done, but now I need to know what is best practise to save files that are related to database items to disk with Spring and how that is actually done with Spring.
I thought it could be good way to use database table id in folder for example:
context_path/table_name/id/filename.file
There are three options:
This is the case not only with spring, but with any application.
Your approach to save the file in a directory which has the name of the ID of the row in the database is pretty good. There is no good way to make this really 100% transaction safe (filesystems don't really understand the concept of "transaction" or "two phase commit".
Just make sure that the context_path
is configurable so the data can be moved around easily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.