views:

34

answers:

1

I am trying to figure out the best way to layout my directory structure so that I can store images from multiple users in a way that would be scalable when used in combination with a database. The database will store the absolute path to each image.

So lets assume I was dealing with users' profile images each of which would have thumbnails of a different size. Would the structure below be sufficient:

/profile_images
    /user_1
      /image_a
        image_a.jpg
        image_a_small.jpg
        image_a_tiny.jpg
      /image_b
        image_b.jpg
        image_b_small.jpg
        image_b_tiny.jpg
    /user_2
        ...
    /user_3
        ...

So my question is whether such an approach would be good. If not, could someone please suggest a better approach that uses a database and filesystem to manage image uploads. Thanks

+1  A: 

Your layout seems sufficient for an application that is expecting moderate number of users and images.

That said, the solution may prove insufficient once the following factors come into play:

  1. The number of user-image combinations grows large.
  2. Your users are spread across the globe.
  3. You need to version the images.
  4. You find that a lot of bandwidth is being spent on hosting the images.

In such a case you might want to look at storing and serving these images outside using something simple as Amazon S3 or using a full fledged content delivery network (CDN).

I believe there are several plug ins available to support S3 storage with minimal fuss. S3Storage is one such (caveat: I have used S3 but not S3Storage).

Hope this helps.

Manoj Govindan
Thanks for replying Manoj. THe issue is that I do expect a large user-image combination and a lot of traffic. Even with S3, I need to know how to organize the buckets so in such a way that it will not become too complex as the user base grows. I know twitter uses S3 and was trying to reverse engineer the urls for their images to try ans figure out how they are accomplishing this feat. If you have some more suggestions, I would like to read them.
Kevin