I tend to stay away from keeping the files in the file system and only storing the metadata in the database. I prefer to keep the files in the database as it greatly simplifies any backup/recovery strategy. The only exception I have to this is if you know you're going to be storing files across multiple devices, which tends to happen if you know you are going to have more images than you can reasonably store on a single logical drive.
Another suggestion I'll make, if you are storing the files in the database, is to store the contents of the file in its own table (i.e. only have the contents and a PK). If you have a file in the table with the entity (say an avatar image in the user table), then if someone were to run a select *
against the user table, then the files would be returned as well, which can be very costly if you are returning a large set of users.
I don't have much personal experience with filestream
in SQL Server, so I can't speak to it very well, but I would think either that or varbianary(max)
would probably be good choices.