0

Problem: I want to add photos to the post, it partially works, but the "images" folder is created separately, instead of in a unique folder marked in green

databaseReference = FirebaseDatabase.getInstance().reference.child("posts")
    
private fun SendLink(url: String) {
    val hashMap: HashMap<String, String> = HashMap()
    hashMap["link"] = url
    databaseReference!!.child("images").push().setValue(hashMap).addOnCompleteListener {
        progressDialog!!.dismiss()
        choosenImages!!.text = "Succesfully added images."
        addImagesBT.visibility = View.GONE
        ImageList.clear()
    }
}

Question: How to move / create "images" folder as a subfolder of green underlined folder?

  • I think you might be interested in this **[answer](https://stackoverflow.com/questions/50147779/how-to-copy-a-record-from-a-location-to-another-in-firebase-realtime-database/50153774#50153774)**. – Alex Mamo Sep 02 '20 at 06:32

1 Answers1

0

In Realtime Database, there are not actually any "folders". There are just nodes that can contain child nodes. There are no operations to "move" data between nodes. What you can do instead is read data from a source node, write it to a destination node, then delete the original node.

If a node that you create is showing up in the wrong location, that means you should probably just change the location where it's being written. Right now, your code is adding new child nodes to randomly generated nodes under "images". If you want to write to "posts" instead, simply change the name of the node where you push the data. Pay attention to how you create the Reference object that you use when you call push() - that reference will be the root node under which the new randomly generated node name will be written.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441