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!

Community
  • 1
  • 1
Kulingar
  • 941
  • 3
  • 14
  • 30
  • possible duplicates: [Storing Images in DB-Yea or Nay?](http://stackoverflow.com/questions/3748); [Should I store my images in the database or folders?](http://stackoverflow.com/questions/713243); [store image in database or in a system file?](http://stackoverflow.com/questions/766048); [To Do or Not to Do: Store Images in a Database](http://stackoverflow.com/questions/815626); [Save image in database?](http://stackoverflow.com/questions/805519); [Where should I store photos?](http://stackoverflow.com/questions/1546485) **Please do a search next time, this question has been asked many times** – mellamokb Jan 25 '13 at 18:49

2 Answers2

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 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 '13 at 18:55
  • Ah, your revision makes more sense. I will think about scalability. Thanks @Guffa – Kulingar Jan 25 '13 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 '13 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.

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123