Where to store profile pictures that the user uploaded?

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 Should these files (images) be stored in Jelastic?

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

Thank you for your attention.

Author: sergioBertolazzo, 2017-10-17

2 answers

Thought about hosting on the machine itself? (On the file system?) Because it would be a cheaper cost than the bench, because this has the cost per space higher than a machine.

The best solution will depend on your context, as you talked about image size, I think the file system is the most suitable. Some facts you can take into account, if it were in database:

1-The Bank will get (perhaps considerably) larger. The simple solution would be serve images directly through the web server(apache and static content in directories, for example).

2 - no transactional control or timing guarantee You can delete the record in the database and not delete the image (or the reverse). If you write the record and there is an error in the insert, for example, you will be left with an orphan image in the folder.

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

 3
Author: Fernando Almeida, 2017-10-17 19:12:00

There are certain considerable advantages to storing images in databases rather than file systems. But the cost of database hosting is higher than the cost of file hosting.

A deeper analysis of your application could assist in your decision-making. The users, amount of access and nature of the images can induce you to choose to store in database if they are small images (smaller size, less spent on hosting-remember?) for generating an access environment to these images more controlled than the file system, but if they are images with high demand for views, it would be interesting to choose to host them in File Systems.

 2
Author: Theotonio, 2017-10-17 18:49:45