Search code examples
reactjsfirebasereduxfirebase-storagereact-redux-firebase

Firebase storage path to store images of a social post


I'm currently working on a social platform where users create posts similar to Facebook or Linkedin. So what I'm trying to achieve is, whenever user create a post they may upload images as part of the post and I want to store them in firebase storage but what I'm not clear is, what type of storage path I should choose from one of the below for uploading images.

Which option is right for user posts from the below?

  1. Create unique storage path for every post of a user and upload respective post images there
  2. Create unique storage path for every user and upload all user posts images there
  3. Create a generic storage path for all users and upload all users posts images there

I'm using Firebase storage and database for this app.


Solution

  • There is no singular correct or best approach here, it all depends on your app's needs and use-cases.

    I typically would use a folder structure with /images/$uid/$postid, for example because it makes it easy for me to delete all images for a specific user, as well as all images for a specific post. But as you can see from that description, that calls out two specific use-cases that might or might not be relevant for your app.