Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store images in database or on file system [duplicate]

Possible Duplicate:
Storing Images in DB - Yea or Nay?

Is it faster and more reliable to store images in the file system or should I store them in a database?

Let's say the images will be no larger than 200 MB. The objective is fast, reliable access.

In general, how do people decide between storing files (e.g., images, PDFs) in the file system or in the database?

like image 232
Crashalot Avatar asked Dec 28 '10 22:12

Crashalot


People also ask

Should I store image 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.

Is it good to store images in database?

Storing images in a database table is not recommended. There are too many disadvantages to this approach. Storing the image data in the table requires the database server to process and traffic huge amounts of data that could be better spent on processing it is best suited to.

What is the best way to store images in a 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.

Can you store images in a relational database?

A relational database table can be used as a cloud object store. Customers who choose this option typically do so to capture images via the app and keep them along with the data in the same repository (convenient for backup and data management).


3 Answers

Personal opinion: I ALWAYS store images on the file system, and only store a filepath in the database. In many situations, databases are stored on fast (read: expensive storage, 15k RPM or SSD drives) storage. Images or other files, typically can be stored on slower (read: cheaper, larger drives, 7.2k RPM drives) storage.

I find this to be the best, since it allows for the database to remain small in size. In general, databases store "data" well. They can search and retrieve small bits of data fast. File Systems store "files" well, they are optimized to find and retrieve larger bits of data fast.

Obviously there are tradeoffs to both approaches, and there isn't going to be a one-size fits all; however, there may be some use cases where storing images in the database is a good thing, if they are all quite small, and you don't anticipate very many of them, and your database is on the same storage medium as your file share, then it probably makes sense to drop the images directly into the database.

As a side note, SQL Server 2008R2 has a FileStream field type, which can provide the best of both worlds, I have not used it yet, so I can't speak to how well it works.

like image 187
Nate Avatar answered Sep 19 '22 12:09

Nate


Store files/images in the database if you require following:

  • Access Control
  • Versioning
  • Checkin/Check out
  • Searching based on metadata

That has been the design of major CMS like SharePoint has been.

However, if your content is much more static and not going to change over time , you can go with files ystem and enable optimizations/cache on the web server.

like image 27
Madhur Ahuja Avatar answered Sep 18 '22 12:09

Madhur Ahuja


With the database approach, you only have one thing to connect to. If your users are distributed, that might be simpler. Note that if the images are not accessed too frequently, the efficiency issues might not matter.

like image 30
davep Avatar answered Sep 19 '22 12:09

davep