Where to store profile images that the user uploaded?

1

I have a JAVA application that needs to store profile images that the user uploaded.

//no meu LOCALHOST eu uso esse caminho e funciona perfeitamente:
File arquivo = novo File("C:/myProject/uploads/profile_images");

So now I want to deploy this project, I'm using the jelastic environment and the question is:

Where are these files (images) to be stored in Jelastic?

  • I've tried the same code but it did not work.
  • I already tried to save the files in the WebContent folder, it works perfectly, but when I expand a new .war file, the files that the user sent will be overwritten.
  • I read about saving files in mySql, is it a good practice?

Thank you for your attention.

    
asked by anonymous 17.10.2017 / 18:59

2 answers

3

Did you host the machine itself? (In the file system?) It would cost cheaper than the bank because it has the cost per space higher than a machine.

The best solution will depend on your context, as you said in image size, I think File System is the most appropriate. Some facts you can take into consideration, if it were in database:

1 - The Bank will stay (perhaps considerably) higher. The simple solution would be to direct the images through the web server (apache and static content in directories, for example).

2 - There is no transactional control or synchronism guarantee You can delete the record in the BD and not delete the image (or the reverse). If you save the record and there is an error in the insert, for example, you will have an orphaned image in the folder.

3 - Increases the complexity of the DB, because now the backup will also have to consider the table of images

    
17.10.2017 / 21:12
2

There are some considerable advantages to storing the images in a database instead of file systems. However the cost of database hosting is higher than the cost of hosting files.

A more in-depth analysis of your application could aid in your decision making. The users, the number of accesses and the nature of the images can induce them to opt for database storage if they are small images (smaller size, less expense with hosting - remember?) For generating an environment of access to these images more controlled than the but if they are images with high demand for views, it would be interesting to choose to host them on file systems.

    
17.10.2017 / 20:49