0

When I upload an Image, it is automatically update to database child(user.uid).child(newImage).childAutoID.setValue() This is my json node

Users
  WOhpPzlHCzYximWyBXas3Prg2rL2
     NewImage
       -KSE4ZcvqhFeWmuRQjjI
       -KSEGLazKbfPePkCBFbe
       -KSEGNVimH7GACRyXbo4
       -KSEGO4gfLGOv0erTXA5
       -KSENPeq7Oa5cru7gKum

Inside one autoID, This is the Json tree

-KSE4ZcvqhFeWmuRQjjI
    DownloadUrl:  "abcd.com"
    timestamp:    21-09-2016

When I try to get value from DownloadUrl, I use child("Users") but can't child through user uid, anyways I can't child through autoUID which is created by Firebase. Does anyone have any experience. Thank you

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

Swift 2:

FIRDatabase.database().reference().child("Users/\(FIRAuth.auth()!.currentUser!.uid)/NewImage").observeSingleEventOfType(.Value , withBlock : {(imagesSnap) in 

    if let imagesDict = imagesSnap.value as? [String:AnyObject] {
       for each in imagesDict{
           print(each.0) // your autoId
           print(each.1) // your imageDetails for that autoId  
           }
    }
})

Swift 3:

FIRDatabase.database().reference().child("Users/\(FIRAuth.auth()!.currentUser!.uid)/NewImage").observeSingleEvent(of: .value, with : {(imagesSnap) in

        if let imagesDict = imagesSnap.value as? [String:AnyObject] {
        for each in imagesDict{
        print(each.0) // your autoId
        print(each.1) // your imageDetails for that autoId
        }
       }
     })

But if you are looking for the autoID that contains a specific key value pair Read last part of this answer

Community
  • 1
  • 1
Dravidian
  • 9,945
  • 3
  • 34
  • 74