开发者

Saving pictures on server

开发者 https://www.devze.com 2023-01-22 10:47 出处:网络
I\'m programming site for ren-a-car company, and I need to save exactly three pictures for every car. What is better to store in database ( table description) pa开发者_StackOverflow中文版th to images

I'm programming site for ren-a-car company, and I need to save exactly three pictures for every car. What is better to store in database ( table description) pa开发者_StackOverflow中文版th to images and images save in some folder OR to save pictures in table (MS SQL )?


The main question is: how big are those pictures on average??

A thorough examination by Microsoft Research (To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem) has shown:

  • that it's better to store stuff inside your SQL tables as long as the data is typically smaller than 256 KB
  • that it's better to store on filesystem if the elements are typically larger than 1 MB

The in-between is a bit of a gray area....

So: are you pictures mostly more than 1 MB?? Then store on disk and keep a reference. Otherwise, I'd recommend storing them inside your database table.


Better to save the path to the picture (and probably even better just the filename usually). By storing the picture in the table, you are increasing the size of the tables and therefore increasing lookup time, insert time, etc for no apparent gain.

The other thing is that you say you need to save exactly 3 pictures for each posting, so this makes me think you're using fields in your posts table such as pic1, pic2, pic3. You might want to normalize this so that you have a post_pictures table that links each post with a picture.

For instance: post_pictures: post_picture_id | post_id | picture_filename. (you can even get away with having just two fields).


Depending on the horsepower of your server farm, save in SQL. I have set the up fields as varbinary(max).


What advantage do you have in storing the images in database? Can you think of any use of the image data being stored in a DB?

I suggest you store the images in file system rather than database. You can use the database to store meta data of the images (path,keywords etc) in the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号