Whenever you save your valuable images (supose you've plenty of them) would you store then as blobs inside your Database, or as files? Why?

Duplicate of: http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay

It's my job to opt for storing them as files, and keep path within the database. In my experience, it is a much simpler and much more natural approach than pushing them in to the database as blobs.

One argument for storing them within the database: much simpler to complete full backup copies, but that is dependent in your needs. If you want to have the ability to easily take full pictures of the database (such as the images), then storing them as blobs within the database is most likely what you want. Otherwise you need to pair your database backup having a file backup, and in some way attempt to connect the 2, to ensure that if you need to perform a restore, you realize which pair to revive.

It is dependent on how big the look.

Microsoft Studies have an interesting document about them

I have attempted to make use of the db (SQL Server and MySQL) to keep medium (< 5mb) files, and things i got was a lot of trouble.

1) Some DBs (SQL Server Express) have size limits

2) Some DBs (MySQL) become mortally slow

3) If you need to display a listing of object, should you inadvertedly do Choose * FROM table, a lot of data will attempt to increase and lower in the db, producing a deadly slow response or memory fail

4) Some frontends (ruby ActiveRecord) have very large troubles handling blobs.

Only use files. Don't store all of them within the same directory, apply certain method to use them several dirs (for example, you could utilize latter chars of the GUID or latter numbers of the int id) after which keep path on db.

If I am running on a single web server and can only be running on a single web server, I store them as files. If I am running across multiple webheads, I place the reference demonstration of the look a database BLOB and cache it as being personal files around the webheads.

Given that you desire in order to save a picture together with a title, description, produced date, produced by, etc., you will probably find it easier to save inside a database. This way, things are together. Should you saved this same info and saved the look like a file, you would need to retrieve the entire "image object" from two places...and in the future, you will probably find yourself getting syncing issues (some images not found). Hopefully this will make sense.

Now you ask ,, does the application handle BLOBS or any other files like other application data? Do your customers upload images alongside other data? If that's the case, then you need to keep BLOBs within the database. It causes it to be simpler to support the database and, in case of an issue, to recuperate to some transactionally consistent condition.

But when you mean images which are members of the applying infratstructure instead of user data then most likely the reply is, No.

The performance hit of the database server is really a moot problem. If you want the performance advantages of personal files system, you just cache it there around the first request. Subsequent demands may then be offered from the file system with a direct link (which, just in case of the web application, you can rewrite the HTML with before eliminating the output buffer).

This gives the very best of both mobile phone industry's:

  • The authoritative store may be the database, keeping transactional and referential integrity
  • You are able to deploy all user data by simply implementing the database
  • Draining this cache (e.g. with the addition of a web server) would only result in a temporary performance hit even though it is filled again instantly.

There's you don't need to constantly hammer the database for stuff that will not change constantly, however the important factor would be that the user information is all there and never scattered around different places, making multi-server operation and deployment an overall total mess. I am always promoting the "database because the user data store, unless of course" approach, since it is better architecturally, and never always reduced with effective caching.

With that said, a very good reason to make use of the file system because the authoritative store could be when you wish to make use of exterior independent tools for being able to access it, e.g. SFTP and whatnot.