Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice For Saving Images in SQL Server

There are many times that I wanted to save an image to an SQL Server. I have read some practices for saving images :

1) upload and save image to server, save the path inside the table

2) save image as binary

3) save image as base64 string

4) using BLOB(i haven't researched how it works)

Do you know which "way" is faster when you request from server an image? Do you know which "way" is better so as not to make SQL server slower? Do you know any other "way" which is better from the above?

Thanks!

like image 416
Emmanouil Chountasis Avatar asked Mar 24 '23 12:03

Emmanouil Chountasis


1 Answers

Microsoft has done some research on this topic and has concluded that it depends on the size of your image. If most of your images are < 256Kb, you should probably use VARBINARY. On the other hand, if they are above 1Mb, then you should use a FILESTREAM (which is usually stored on the filesystem outside the database file).

If your images are linked to other data, it's often useful to separate the records itself from the images into different tables (i.e. create an Images table) so that the table with the data remains small and easy to manipulate.

like image 57
Cameron S Avatar answered Mar 30 '23 01:03

Cameron S