-
1. Re: Persist images in the database or save it in the hard disk?
shane.bryzak Apr 22, 2010 5:00 AM (in response to nifs)There's not really a
best
way, both have their advantages and disadvantages. Storing images in a database gives you the advantages of being able to use database indexes, writing the image as part of a db transaction, being clustered (if your db is set up that way) etc. Disadvantages are that you possibly need to do some specific db planning/tuning if you plan to store a lot of images, and that if your database is on a separate server then you have to add network latency to the performance equation.Storing images as files has it's own set of pros and cons. One possible advantage if you don't have any security requirements for your images is that you can host them in a location that's accessible directly by your web server (typically Apache HTTPD) rather than your servlet container (better performance). On the other hand, you have to come up with a system for naming/indexing the images, and probably still have to store at least some kind of reference to the image file in your database. And then you still have to deal with any file system permission issues or other file system restrictions (not to mention backing up and dealing with possible file corruption), which might otherwise be easier to handle from an application developer's point of view if the images are stored in a db.
There's probably other things that I can't think of right now, but there's a start. ;)
-
2. Re: Persist images in the database or save it in the hard disk?
nifs Apr 22, 2010 6:08 PM (in response to nifs)Thank you so much Shane, i've got the idea!!!
-
3. Re: Persist images in the database or save it in the hard disk?
sean.tozer Apr 22, 2010 9:24 PM (in response to nifs)I'd agree with Shane that there are certainly pros and cons to both approaches. However, in general, I tend to lean towards storing images on the file system rather than in the database. Both certainly would work.
For one thing, storing them on the file system means that you, as an administrator, can view the images as a regular file. That can be advantageous. It also allows you to do per-file archiving and versioning in a fairly straightforward manner. It does mean that you would have to handle any database ACID requirements yourself, which might or might not be a big deal, depending on what kind of application it is.
Without knowing more about the specifics of what you're doing, it's hard to give more than general advice. There is no one true way.