0

I am creating my web application and need your suggestion about organizing media files and folders. So what I have right now is structure like this:

In the root I have folder images/myappName/ where I am going to save all files related to this application. This application will have different posts and each post can have few images (6~10), so I don't know how properly do the saving part. I have two options:

1) I can create each folder for each post, name them their ID, in images/myappName/ and save images for each post under their folder, something like if post's id is 1154 image container folder will be images/myappName/1154/example.jpg

2) Save all images at the same location, but their name will start by their ID. Something like if post ID is 1154 the image names will be images/myappName/1154_example.jpg

So what do you recommend guys? Which one is better option, what downsides each option can have and what else can you recommend?

Volter
  • 173
  • 2
  • 4
  • 12

1 Answers1

1

if your app is going to store user's images and files, you should consider storing these into a DB as LOB data instead of using the file system, so if one day you decide to cluster your app, it can scale.

Update- if you don't want to store blobs, you can have the best of both worlds storing file metadata in the db. So you'd have freedom to add tags to your files without the worry about how these files must be organized physically in the file system

Leo
  • 6,480
  • 4
  • 37
  • 52
  • WoW, I have never heard idea like this, I am interested in it. My another app, under the same domain, will give users ability to upload and save images, but on this app, only admins will upload and store images for posts. So for LOB do you recommend using another mysql database or same database but different table? – Volter Feb 16 '14 at 14:43
  • all eggs in the same basket = you'll have to stop all your apps if anything goes wrong with the table ;-) – Leo Feb 16 '14 at 14:48
  • "all eggs in the same basket" -> I guess you mean it for BLOB, but if I decide to use file system which option do you recommend from above: Same folder, or different folder for each post? – Volter Feb 16 '14 at 14:56
  • if you have one instance per app, then you can shutdown each instance when you need to stop each app for maintenance. On the other side, if you store everything on the file system, it's one basket and you'll lose everything. And it will be harder to scale in a cluster environment. – Leo Feb 16 '14 at 14:58
  • even databases you can cluster, minimizing downtime. For a file system, I think it's worse – Leo Feb 16 '14 at 14:59
  • Thanks for help, I found this article on stackoverflow, I think it describes advantages and disadvantages of using BLOB http://stackoverflow.com/questions/14215701/which-is-the-best-method-to-store-files-on-the-server-in-database-or-storing-th – Volter Feb 16 '14 at 15:05
  • maybe you could add more info in your question, so we can know exactly what you're looking for. what kind of app you're developing? – Leo Feb 16 '14 at 15:20
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47599/discussion-between-volter-and-leo) – Volter Feb 16 '14 at 15:31