User images - database vs. filesystem storage

19,270

In general, it is better to store files on the file system. File systems are already tuned for storing files. However, this does have its drawbacks, particularly in terms of management, backup, restore and it is somewhat of a flimsy tie between a varchar file path field in the database and a file in the file system. What database system are you using? I think if you are using SQL Server 2008, that the new FileStream type gives a very good method for storing files in that database.

Edit: Note I'm really talking about more generally about storing files in the database. There is some extra complexity involved in trying to store images you intend to display on HTML pages in the database.

Share:
19,270
3142 maple
Author by

3142 maple

Updated on June 05, 2022

Comments

  • 3142 maple
    3142 maple almost 2 years

    I’m writing an upload function in .NET for presentation images on user profiles. I’m choosing between two different ways of doing it, and would like to ask on advice and opinions as to the pros and cons.

    1. Store the images directly on the file system

    2. Store the images in the database

    So far I’ve been mostly pro the first option – naming the images after the usernames, as each user can only have one presentation image. Then I do a check in the designated path if the user has an image, if not display a default “no image”-image.

    Another thing I like about this is that it saves space in the DB – the DB will be pretty heavy without the extra binary load.

    I’m sure there are other aspects that I’ve not thought about, so I’d like to hear your opinions on this. If anyone’s got a radically different solution to the problem, please share that as well!

  • BobbyShaftoe
    BobbyShaftoe about 15 years
    Yeah, somehow I misread the bit about images. I leave my post as most of the files in db vs file system discussions on SO don't usually discuss FileStream. I think for images you mean to display, store them as files.
  • wiwulo
    wiwulo about 15 years
    Yes, the time to access to files explodes above 1000 per folder. You could say you don't mind. But indeed, your administrator will care about fast backup/restore. The efficient solution is to make folders