0

Possible Duplicate:
Storing Images in DB - Yea or Nay?

Friends,

I have a requirement to show dynamically changing images in DataList. what I did was I am storing the images in DB as image datatype and retrieving the images. Is that good technique to store images in DB?

FYI, user can upload the images.

Regards, Abhi

Community
  • 1
  • 1
Tony
  • 141
  • 4
  • 21
  • user has to eneter Image name before uploading image , and I am not allowing same image name. – Tony Jun 15 '12 at 10:39
  • The storing the image to the database is only more simple and less complicate, but the better place is the disk (that is also a database). If you store in the disk, the thinks is a little more complicate on programming, you need to add reference on the database to know also some other thinks, make correct lock, retrive, delete etc, but this is the better place. – Aristos Jun 15 '12 at 10:55

7 Answers7

3

The answer is - it depends... Studies have been done (http://research.microsoft.com/pubs/64525/tr-2006-45.pdf) which have basically concluded if objects are larger than one megabyte on average, NTFS has a clear advantage over SQL Server. If the objects are under 256 kilobytes, the database has a clear advantage. Inside this range, it depends on how write intensive the workload is, and the storage age of a typical replica in the system.

Dave
  • 3,581
  • 1
  • 22
  • 25
0

I would store them as physical files on the server, but store the file path in the database, not the actual image. Storing the image in the database will increase it's size dramatically over time.

Arran
  • 24,648
  • 6
  • 68
  • 78
  • If a file is associated to a unique entry with an ID in a database, you can also just use the ID for the name of the file stored. In this way you don't need to store the path in DB. – Laurent W. Jun 15 '12 at 10:40
0

Images sizes will increase your DB size unnecessarily so not good practice to store it, instead store the file path in your db, which is not that big. Storing image in DB should be done if you have some strong requirement or use case.

maaz
  • 4,371
  • 2
  • 30
  • 48
0

The thing you have to address if you store paths etc. is maintaining referential integrity with your images. What if somebody moves files, what if somebody uploads a new file with the same name (I'd suggest uploads get renamed to reflect some kind of key rather than keeping their original name of bob.jpg). You'll need to look at segmenting your directories etc. to keep the list sensible. Finding the images may be harder than if you store them in a DB also.

However, on the up side, you can form a CDN based on distribution of your images over diverse servers, subdomains, cloud etc. if you don't jam them all in your database

Jeff Watkins
  • 6,343
  • 16
  • 19
0

Depends on the size of the images and the DB you use.

For SQL Server it is pretty bad idea if they are larger than 1MB and you do not use the NTFS Filestreams for storage of your BLOB fields. See for example http://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/

If you have a document oriented database like Couch DB it might be ok.

schlenk
  • 7,002
  • 1
  • 25
  • 29
0

I would store them as physical files on the server, but store the file path in the database, not the actual image. And search the file as per the location store into Databasse. Storing the image in the database will increase it's size dramatically over time.

Saroop Trivedi
  • 2,245
  • 6
  • 31
  • 49
0

Storing them in database is also useful if you need to scale your site across multiple web servers.

If they are static then there is no use as they can be deployed with your site but things like avatars are generally better stored in the DB so they are available to all cluster members.

westo
  • 575
  • 2
  • 10