Question

I want to create an image gallery and obviously, it must have images in it.

Somehow, I've been wondering about what's better between storing the images in a directory and retrieve them one by one or store them in the database as a BLOB data?

Thank you people! Cheers!

I am willing to learn either of the methods so please enlighten me.

No correct solution

OTHER TIPS

This question has been debated for many years. Advocates will make strong cases for each. Neither side as ever been definitively proven to be right in all cases.

Both methods break down when the number of images that you need to warehouse gets very large. Both databases and file systems have become better in the years since I bench marked both options against each other. At that time, you could fix the performance hit on the "file system" option by creating a hierarch of directories instead of putting them all in one directory. By now, file systems may have been optimized so that they don't choke when the number of directory entries gets large.

This is truly a "your mileage may vary" situation. Factors will include what file system will you use vs. what database engine will you use, how many images, what average size? Will you be "tagging" the images in the database as well as storing them?

Typically, you have to just try all the options until you find something that works in your configuration.

Definitely stress test it. If you think you need to store one million images, don't test with five and assume that it will scale. Test it with at least a million images, if not with two or five million.

That said, if you only need to store 1,000 images (or less) maybe even 10k or less and if you need to index the images by attributes like date, location, subject matter, etc. then at the risk of offending many well meaning people, I am going to recommend storing the image as a blob in the database. The convenience of using the database to join the image to the meta data will outweigh anyone's performance concerns at that scale. When you store the metadata in a database with a pointer to a file in the file system, it is too easy for things to get out of sync. The file gets moved, renamed, deleted etc; your database wont know and now your system is broken. Using a database will insure the integrity of your data, including the images for you.

First you will need to upload file in any predefined folder and than you can store name of that file in your database(with is varchar data type).

And when you will fetch those records, use that name to recreating image path wherever application required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top