3

Possible Duplicate:
User images - database vs. filesystem storage

Hello ! Where should i store photos for a facebook-like app ? locally on the server in a folder or upload them to a database ? I am not intending to make this app commercial .

Community
  • 1
  • 1
Alex
  • 10,869
  • 28
  • 93
  • 165
  • possible duplicate of [User images - database vs. filesystem storage](http://stackoverflow.com/questions/585224/user-images-database-vs-filesystem-storage) **OR** [Store pictures as files or in the database for a web app?](http://stackoverflow.com/questions/561447/store-pictures-as-files-or-in-the-database-for-a-web-app) – ajreal Dec 26 '10 at 13:41

2 Answers2

3

Store images in file system(folders) and store path in database.


EDIT:

Found an interesting article about How Facebook handle image storage:

Facebook: Needle in a Haystack: Efficient Storage of Billions of Photos

Some facts from above article:

  • Photo facts:
    • 6.5B photos in total
      • 4 to 5 sizes of each picture is materialized (30B files)
      • 475k images/second
        • Mostly served via CDN (Akamai & Limelight)
        • 200k profile photos/second
      • 100m uploads/week
    • Stored on netapp filers
Naveed
  • 41,517
  • 32
  • 98
  • 131
  • :) Indeed recommended read. I guess this is the right URL http://www.facebook.com/note.php?note_id=76191543919&comments I suggest to take small steps, start conventional, and when you find your site is flooded with uploads and requests beyond the limits -- go for something like this. – Nishant Dec 26 '10 at 14:07
  • The James Hamilton post is very interesting, and it's two years old! I guess they multiplied all this by a big number now :-) – Simon Mourier Dec 26 '10 at 14:23
0

I would prefer files to be stored in file-system and data to be stored in database. So, what I will do is I will upload the file and save it in file system.. in a directory. Say, /home/username/appfiles/ and in data base I will have a reference to it. Say, under column image_location: /home/username/appfiles/image_file_name.

What I will also do is I will rename the file by appending a timestamp to make sure two files with same name does not get over-written.

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • imo it's more practical to store the path like /appfiles/image_file_name and store the prefix somewhere else, so when you move the files for some reason, you can just change the prefix instead of the whole database. – Zoltan Lengyel Dec 26 '10 at 13:53
  • right. That was just a bonus suggestion. I keep file_storage_directory as a configurable propery. And then I store the file-path relative to it, in DB. When I need to pull out the file, I just concat these two. In case I have moved my files to somewhere else, I will just update config settings. done. – Nishant Dec 26 '10 at 14:00