What is the best strategy for uploading and using images in JSF?
I do not want to use blob field in the database, so how do I solve the image storage folder problem, since the .war file is closed.
What is the best strategy for uploading and using images in JSF?
I do not want to use blob field in the database, so how do I solve the image storage folder problem, since the .war file is closed.
There are two approaches to saving commonly used upload files: saving to DB or to a out of project folder
It is very common to see, who is starting to work with java web projects, the upload being saved in the same project directory. In other words it is common for people to save the files inside the same folder where the deploy was performed, in Tomcat's case it would be inside the webapps folder.
Why is this a bad practice?
Who takes care of the folders created inside a server, is himself. It can very well erase, rewrite, copy or do as you please with the files found there.
In this case the correct would be to have a folder outside the deploy area of the server for example. Something like: "C: \ uploads"
The advantage of this approach is that when backing up the database, the image is automatically backed up. Another advantage is the fact that the code is simpler, to search for an image just a simple query.
The disadvantages would be that:
The advantages of saving files to a folder would be:
In the case of JSF you will run into the problem that the components, natively, only display images that are inside the server (at least those that I know, others may already have the look-out function).
There are solutions you could do to display the images: