19

We are developing an E-commerce website using ASP.net and SQL server. The customer can view and order a wide variety of switches and light fittings.

As we need to display images of these products for each category, the number of images we need to display may rise to over 500. We are a bit confused by whether we should save these images as Image type in SQL, or whether it's better to store the path of the image. In the latter case, is storing all images under single folder better?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Supreeth sup
  • 279
  • 1
  • 4
  • 15
  • 5
    [storing-images-in-db-yea-or-nay](https://stackoverflow.com/questions/3748/) – juergen d Apr 20 '15 at 11:23
  • 5
    http://research.microsoft.com/apps/pubs/default.aspx?id=64525 (btw: `image` as a datatype is deprecated, you should use `varbinary(max)`) –  Apr 20 '15 at 11:30
  • Though you can save the images in the database, but try to save only the image (or other file) file name and path in the database and store corresponding file in app folder or any other specific folder in server. Thank you. – BAdmin Apr 20 '15 at 11:33

6 Answers6

13

The image data type has nothing to do with images. I don't know why it exists. It is legacy.

Store the images like you would store any other blob: varbinary(max).

The issue whether to store blobs in the database at all has been discussed before. Note, that the answers there are very opinionated and subjective. It is clearly wrong to say that one should always store blobs inside out outside of the database.

usr
  • 168,620
  • 35
  • 240
  • 369
10

You can use the below data types for BLOBs on sql server:

Binary: Fixed size up to 8,000 bytes.

VarBinary(n): Variable size up to 8,000 bytes (n specifies the max size).

VarBinary(max): Variable size, limit of 2 GB.

What Is a BLOB?

Pixelomo
  • 6,373
  • 4
  • 47
  • 57
Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
4

I would suggest you could save the image urls in the database, against your product id. But if you are requesting upto 500 urls at a time, I would suggest perhaps introducing a CDN in the middle to cache the Image URLs. Will have a big impact on performance

Lee Swainsbury
  • 365
  • 2
  • 9
2

Storing Image to Folder and path of that file to sql server is good idea. But it may cause same name of file and replaced. so saved with timestamp. I think it will help you otherwise do another way that saving to Image Datatype of sql server.

To Save Data to sql server Image Datatype Follow Guildline on below link

Go to Link

0

Let's think about this. If you do store in a blob field, make sure you create a separate file group for that data. If you decide to store as a path. Use filestream. The database will manage the path. It will be handled in transactions. It will be backed up with the database.

vbjay
  • 107
  • 10
-1

Saving image directly into the database is not that good idea.Most better will be saving image and media/document files to s3 bucket/cdn and that much cost you dont want to pay.save images into folder and save its path to the database with varchar datatype