5

I want to store user's profile picture on Firebase storage.

My Firebase database structure is like below.

users
  ㄴ KXkVAYQOV92tW27Wk0C
       ㄴ uid: "EAGZwcgvgAcgErO7rfm7IHI91fk2"
       ㄴ sex: "F"
       ㄴ age: 24
  ㄴ KXkVR1rc2riXyGFl69E
       ㄴ uid: "alE4qM1vg2c9OrW5lVo7IvQk02Hv"
       ㄴ sex: "M"
       ㄴ age: 21

And now I'm wondering how my Firebase storage file structure should be.

Idea 1:

images
  ㄴ users
      ㄴ EAGZwcgvgAcgErO7rfm7IHI91fk2
           ㄴ profile.png
           ㄴ something.png
      ㄴ alE4qM1vg2c9OrW5lVo7IvQk02Hv
           ㄴ profile.png
           ㄴ something.png

Idea 2:

images
  ㄴ profile
      ㄴ EAGZwcgvgAcgErO7rfm7IHI91fk2.png
      ㄴ alE4qM1vg2c9OrW5lVo7IvQk02Hv.png
  ㄴ something
      ㄴ EAGZwcgvgAcgErO7rfm7IHI91fk2.png
      ㄴ alE4qM1vg2c9OrW5lVo7IvQk02Hv.png

Which one is best practice for Firebase storage in performance and usability?
Any advice would be thankful !

Edit:
As Lirianer's comment, Database should looks like below.

users
  ㄴ EAGZwcgvgAcgErO7rfm7IHI91fk2
       ㄴ sex: "F"
       ㄴ age: 24
  ㄴ alE4qM1vg2c9OrW5lVo7IvQk02Hv
       ㄴ sex: "M"
       ㄴ age: 21
Community
  • 1
  • 1
wonsuc
  • 3,498
  • 1
  • 27
  • 30
  • What I tend to do is what you did in your "Idea 1" example, that way is easier for me to remember routes. Also in the database I would use the uid as keys for the users and save the download path of the profile image as a string. – Lirianer Dec 06 '16 at 20:03
  • In my case, I'm storing images in Storage that are grouped under some node such as Root->ImageGroup1. I upload the image to Storage and get the Storage URL back in onSuccess(). Then I write a structure to the Database using a model representing the image. The model contains two fields: the URL of the image and the UUID of the user. I do a push() to get a key created and then setValue(imageModel) to write it to the database. – Lucy Dec 07 '16 at 05:04
  • @Lirianer Thank you Lirianer, I agree with your opnion. – wonsuc Dec 07 '16 at 17:54
  • @Lucy Thank you. It was helpful advice. – wonsuc Dec 07 '16 at 17:54

1 Answers1

3

I solved it. The idea 1 was suit for my case.

wonsuc
  • 3,498
  • 1
  • 27
  • 30