I am working on an E-commerce application and I need to upload things such as product name, price, description along with an image of the product to the Firebase Realtime Database and then load it once the app is launched. I was planning on using 3 separate nodes that store items in one and item price in the next, then finally images of the product, but I am unsure as to how to store individual images inside a node that is associated with the products, is there a better way of doing this, that someone can share?
CodePudding user response:
You can do it two ways;
- Just add the public link in one your database field, of that image/file and access it.
Or
- You can add you image/file in firebase storage. And then you can access ot via your FirebaseStorage liberary.
And for the text part, you can just click on plus icon in database's field and write your desired field and its value.
CodePudding user response:
I have asked you a question in the comments section:
To understand better, the $49.99 price is for Shirts, right? And you want another node called
ItemsUrl
where0
will hold the URL of the Shirts?
And you answered:
Yes that's what I want to do
But please note that this is not the way you should interact with the Realtime Database. Storing each field into an array, in separate nodes, sounds not like the best solution. What I recommend you instead, is to create a single node of products, and add each field inside a separate product object:
Firebase-root
|
--- products
|
--- $pushedId
|
--- itemName: "Shirt"
|
--- itemPrice: "$49.99"
|
--- itemUrl: "https://..."
To read the data, you can then use one of my answers from the following posts: