2

Currently, I am making a WPF + C# application. I should store images on server, but I don't know if I should store the image as binary or base64.

Which of the above methods is the best?

I using SQL Server for store database!

Thankyou!

ElGavilan
  • 5,747
  • 16
  • 24
  • 35
Son Le
  • 191
  • 4
  • 13

2 Answers2

4

There's a really good paper by Microsoft Research called To Blob or Not To Blob.

Their conclusion after a large number of performance tests and analysis is this:

  • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

  • if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

  • in between those two, it's a bit of a toss-up depending on your use

If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the images in the "regular" table - keep them in a separate table. That way, the regular table can stay lean and mean and very efficient, assuming you don't always need to select the images, too, as part of your queries.

But if you choose to store the images in your SQL Server database, by all means store them directly as binary values - do not Base64 encode them all! That's madness, and will blow up your image size substantially, for no real benefit.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
-1

Instead of storing the bytes of the image you could save the file in a specific folder and save the path in the database

Patrick
  • 706
  • 9
  • 24
KibGzr
  • 1,773
  • 8
  • 11