2

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

Pretty straight forward, I am hosting a site where users can upload pictures, and I have a .net File upload control working appropriately.. I'm just wondering what methodology I should use to store them on the server..

  • I can use the SaveAs() method off the FileUpload control which saves it as an actual file..
  • I can break the image down to a Byte[] and store it in the database for access.

I believe the real question here is.. Do I want the load on IIS or Sql Server 2008 R2?

What's the general consensus on which methodology I should use and why? Thanks!

1

2 Answers 2

5

There is no general consensus, because neither method is ideal.

Storing the images as files means that it becomes harder to scale the application to run on multiple servers. Then you would need a SAN/NAS to store the files instead of a local disk.

Storing the images in the database means that you are using a lot of the cache space for image data, slowing down other queries, and it also increases the size of the database, and the backups. It also means that you have to serve the images through a page, you can't just request the file directly.

So, it comes down to how much images you will have, and how scalable you need the application to be.

3
  • Thanks for addressing both sides @Guffa We are already looking at a SAS / LUN (I don't speak much infrastructure lol). But I wonder if there's another method that's better? Which method would YOU use?
    – Kulingar
    Jan 25, 2013 at 18:55
  • Ah, your revision makes more sense. I will think about scalability. Thanks @Guffa
    – Kulingar
    Jan 25, 2013 at 18:58
  • @Kulingar: What I would use would depend on the sitation. I have used both. Currently we are building a system with one web server storing images on a NAS, and multiple web servers loading them from the NAS, resizing and caching them before serving them.
    – Guffa
    Jan 25, 2013 at 19:01
3

Avoid getting them in the database. That will make your DB a lot larger in size just because of a few files. That also affects the backup size.

I do not see any real gain on having the actual file bytes in the database. If you have the physical path to the file in the file system, that would suffice.

That also allows you to have your own backup strategy for the files.

Not the answer you're looking for? Browse other questions tagged or ask your own question.