views:

145

answers:

2

In my web application, each user will have a logo. I am pretty sure each user will also have a photo gallery in the future. What is the best way to set up a directory structure for managing user logos and possibly other assets such as photos? Also would be good to get people's opinions on what to store in the database. My application is a Rails app.

Just to be clear, this web application will need to scale to possibly hundreds of thousands of users.

A: 

If it's a small web application and you have a database:

One folder containing all avatars (logos). In the database you set the filename of the avatar. Also another folder containing all photo's in a gallery. In the database you have one entry for each asset, pointing to the resource and user.

If it's a bigger, or growing, application, you can automatically create more folders (scripted: each 100 files create a new folder), or even load-balancing by having more than one server solely providing assets.

If you don't have a database:

Create a folder per user, which contains their avatar and assets. This one does not grow, since you don't have a database which points to the user-assets: if you have more than one server, you can't say "which" server the resources are on.

Pindatjuh
+2  A: 

There are plugins that offer drop in functionality for the things you're looking to do.

Essentially they work similarly to what Pindatjuh suggests. But you should check out attachment-fu and paperclip to see how the others have done it.

EmFi
ok, i didn't know those handled dir structure. will check out
Tony
Not so much that they handle the directory structure. But they provide sensible defaults for placing and retrieving attachments such as images.
EmFi