2
votes

I understand how to upload/download images. Wondering best practice how to manage this data inside firebase console?

We mostly going to upload pictures/videos and send it between users via private chat/group chat within our app.

So I started to create this:

enter image description here

  1. should i add pictures to users e.g:

     /users/<userId>/images/<image-file>  
    
  2. how would be good to share a picture on chat-group?

     /groups/groupId/images/<image-file> 
    

this is how our firebase structure deals with group messages

  /groups/<groupId>/<messageId>

If expanding messageId u see the message,userId(who wrote the message and timestamp)

enter image description here

suggestions would be welcomed

Thanks.

1
The biggest reason for picking a specific folder structure is so that you can secure access to specific files using security rules. I'm not sure why you tagged for firebase-database too. How does that play into your question?Frank van Puffelen
i added firrbase database to get insights and best practices that might be applied to firebase storage. bout security.. simple requirements.. on private chats only the two persons can access the files, on groups only the group participates can access the files. how.would u recommend to structure it according to that?rayman

1 Answers

2
votes

According to me, every pic (or file) uploaded by user is User's own property, so what you can do is, your point number 1 is the correct way to implement. You can even apply security rules to it. You don't need to worry about architecture, as it is already flat. Nothing to worry about it.

So, you upload file to User's folder and you will get a link to that file and you can store it in Firebase Database. I hope you are clear with your point no. 1

Now, for point number 2. Your Firebase Database will have groups object, that will hold the chats users do. If you want to share the image to group, in this case too, you will upload file to your folder on Firebase Storage, you will just share link to it in Group Chat.

Overall, You upload files to Firebase Storage, store and share the link to it in Firebase Database.

Hope you are clear with both of your points. Ask if you need more clearance on it.