Which data type should be used for saving images in database? [closed]
Asked Answered
P

6

21

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?

Pneumococcus answered 20/4, 2015 at 11:22 Comment(3)
storing-images-in-db-yea-or-nayRoofing
research.microsoft.com/apps/pubs/default.aspx?id=64525 (btw: image as a datatype is deprecated, you should use varbinary(max))Aftertaste
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.Alexanderalexandr
B
16

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.

Bezique answered 20/4, 2015 at 13:0 Comment(0)
N
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?

Natality answered 18/11, 2015 at 12:22 Comment(0)
W
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

Weathered answered 13/5, 2015 at 19:39 Comment(0)
G
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

Grenville answered 3/3, 2017 at 9:56 Comment(0)
M
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.

Mojgan answered 6/4, 2017 at 11:43 Comment(0)
G
0

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

Grenville answered 3/6, 2021 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.