How to structure "files" in "folders"?

Hi, I am looking for experience and similar solutions to a problem.

Authors on our platform upload “files into articles”. They would like to organize their files in “folders”. I was thinking of using Shrine, but I am not exactly sure how to approach the problem.

Authors upload to Articles. For the articles we must have “sources”. These sources are structured as “folders” with “files” They need to organize their folders. But all files are connected with the Article.

My question is - do you know of anything similar to that. Anything I could look for more inspiration on this problem and the solutions others have thought of?


This is outside the scope of Shrine but some thoughts are:

  1. you can use database models to capture the relationships e.g. Articles ->> Sources ->> Files
  2. you can use an extra column in Files to store the sources information. I’m assuming there are 2 models related as Articles has many Files.
  3. you can add a custom key to Shrine’s file metadata to store the sources information.

There may be other ways but which way is best really depends on how you’ll need to access/update the sources info, the frequency of access/update, and future proofing.

@kmitov i agree with what @hmistry said.

I’m not altogether clear of what you are meaning by files, folders, articles and sources. but i can elaborate on what @hmistry has already said.

Manipulating the way things are stored in the bucket

you can manipulate the way in which files are stored in a bucket - read this here: - this is not the best example, but perhaps you can get some ideas:

"articles/564/sources/picture-of-source.jpg"    # notice how the sources are stored within a particular article id?

This would be important if you want to easily delete all the sources for a particular article for example in the bucket using amazon’s ruby libraries. but i don’t think that your users might care how things are stored in the bucket. so you could have a model like this:

Using models and has_many relationships:

# article.rb
has_many: sources

# source.rb
belongs_to: article

so you can allow them to “attach” files things to articles and to sources. users don’t care how it’s stored in the bucket. when the click an article then they should be able to see all the sources associated with a particular article.

i hope that’s making sense?

1 Like