In my web application which I use primefaces+SpringWebflow. I need to add a picture which is scanned or uploaded to every customer registered. I can not think of any good solution to store the files. Criteria is that. I want only application have access to files and it shouldnt be possible to access the images directly. I tried to store the files in database but thats not good idea. i store the path in database. I would like to have relative paths to files. and efficient wy to access the file.
2 Answers
Just store the files in the database. If you try to put them somewhere else, it will be difficult to migrate your application from one server to another, because its data will be spread across multiple sources. Upgrades will be more difficult.
If performance / database size becomes an issue, revisit this decision, but make sure you always measure rather than guess the performance.

- 32,010
- 5
- 70
- 103
-
the problem is not the performance. I have a scanning solution which i read the file from an url. The file get curropted sometimes when i read the bytes and store it to database. Another problem is when i want to display the image i need to read the bytes from the database and store it on the file to disk then display it. And this is not always an easy solution. Primefaces has a functionality to display the file from a bean but it doesnt work in Spring webflow. The other problem is when i backup the database into an sql. the bytes doesnt look good in the sql file. – mettok Dec 23 '11 at 10:30
-
Can you please update the question with more specific details? – artbristol Dec 23 '11 at 10:31
-
If i store the images to DB then when i want to retrieve and display it. i need to read it to a temporary file and display it. Is there any better solution? – mettok Dec 23 '11 at 10:46
-
You can create a special servlet or JSP page for serving just the images. Have a look at this answer http://stackoverflow.com/a/3846095/116509 – artbristol Dec 23 '11 at 10:51
Why is it not a good idea to store the files in DB ? What will happen when you deploy your application on a clustered server environment ? In clustered server environment your solution of keeping images on file-system will not work. You need to think more on keeping storage of images in DB in mind. Just investigate what performance hit you are getting in storage/retrieval of images in DB. try different kind of storage frameworks like nosql DBs. Essentially you can not get away with storing data at a central location I think.

- 7,894
- 2
- 23
- 31
-
Is there any better solution than retrieving image to a file system and display it? – mettok Dec 23 '11 at 10:44