Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store pictures as files or in the database like MSSQL for a web app?

I'm building an ASP .NET web solution that will include a lot of pictures and hopefully a fair amount of traffic. I do really want to achieve performance.

Should I save the pictures in the Database or on the File system? And regardless the answer I'm more interested in why choosing a specific way.

like image 390
StefanE Avatar asked Feb 18 '09 15:02

StefanE


People also ask

Can you store pictures in a SQL database?

SQL Server allows storing files. In this article, we learned how to insert a single image file into a SQL Server table using T-SQL.

What is the best way to store images in web application?

I'd say store all images in an images folder, then store the path of the images in the database, for example if we are doing posts and each post has an image, we could upload the image into /webroot/images/ and save the path /webroot/images/someimage. jpg in the database.

Is it better to store images in database or filesystem?

Generally databases are best for data and the file system is best for files. It depends what you're planning to do with the image though. If you're storing images for a web page then it's best to store them as a file on the server. The web server will very quickly find an image file and send it to a visitor.

How can we store picture or images in database?

To insert images into a database, the database must support images. Images are stored in binary in a table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3 for storing binary data.


1 Answers

Store the pictures on the file system and picture locations in the database.

Why? Because...

  1. You will be able to serve the pictures as static files.
  2. No database access or application code will be required to fetch the pictures.
  3. The images could be served from a different server to improve performance.
  4. It will reduce database bottleneck.
  5. The database ultimately stores its data on the file system.
  6. Images can be easily cached when stored on the file system.
like image 199
Akbar ibrahim Avatar answered Oct 01 '22 18:10

Akbar ibrahim