1

Just a quick message to ask you about how to store images URLs in Firebase Database for later use. Let me explain:

I use Firebase Storage to store Images but store their respective URLs in Firebase Database, separately from Firebase Storage (as I have been reading on here it was the way to do it).
So in Firebase Database I have a "ItemPictures" Node where I want to store up to 5 pictures URLs per Item.

But I don't know what is the best way to store multiple image URLs of a same Item:
- Creating a List with random ids using push() (and then having to manage deleting manually the picture'sURL when it gets updated).
- Creating a "Picture" Object with 5 URLs String values, making it easier to locate and navigate through.

The thing is that later on I will need those URLs to populate a View Pager with the 5 pictures.

Cheers,

Andy

Andy Strife
  • 729
  • 1
  • 8
  • 27
  • http://stackoverflow.com/a/13957446/7012517 reference to your question..! – Shobhit Feb 13 '17 at 04:08
  • Thx for your Comment. I may have forgotten to say that uploading Images, retrieving and then storing their URLs is not a issue. My issue is more about how to structure those URL in Firebase for easy use – Andy Strife Feb 13 '17 at 04:13
  • The Hasan shaikh answer is the best if you don't want to access the image separated from the object. For your explanation, it seems it should work with it, and if for some reason you have a list prior to seeing the object details then you can have a node with the same objects but reduced data docs have a simple example about denormalization (duplicating data) https://firebase.google.com/docs/database/web/structure-data – cutiko Sep 12 '17 at 21:01

2 Answers2

1

using an ArrayList will be a better one

ArrayList<String> images = new ArrayList<>();
                images.add("img1url");
                images.add("img2url");
                images.add("img3url");
                images.add("img4url");
                images.add("img5url");
Hasan shaikh
  • 738
  • 1
  • 6
  • 16
0

The simplest way is to store each image object with unique key and inside it have five keys with values 1,2,3,4,5 respectively. Then you can easily fetch the desired URL for particular image with ID by :

firebaseSnapshot.val().ID.1;
firebaseSnapshot.val().ID.2;
firebaseSnapshot.val().ID.3;
firebaseSnapshot.val().ID.4;
firebaseSnapshot.val().ID.5;

To further improve the performance you can index the image IDs as they are going to grow larger in number. This has been done in the following question.

enter link description here

BILAL AHMAD
  • 686
  • 6
  • 14