title: how to add children in a node in firebase
body: <p>i am trying to upload multiple images at once in the firebase. i have a thumbnail image and three other main images to be uploaded at once , while i am able to upload them successfully in the firebase storage, i find it annoying to reference the path to image in the database. </p>
  
  <p>To upload the images :<br>
  1.) I am performing an upload task to put one thumbnail image along with other data. This is how the database looks like after uploading the thumbnail image:</p>
  
  <p><a href="https://i.stack.imgur.com/Qa30c.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qa30c.jpg" alt="enter image description here"></a></p>
  
  <p>2.) then i run the for loop for uploading other three images to the database, the images are uploaded in the storage. But in the database, under the unique key node i don't get a child containing all the three image urls that i have uploaded in the storage.</p>
  
  <p>This is what i want the database to look like:</p>
  
  <p><a href="https://i.stack.imgur.com/2U2FQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2U2FQ.jpg" alt="enter image description here"></a></p>
  
  <p>my code for uploading images : </p>
  
  <pre><code>    let uid = Auth.auth().currentUser?.uid
      let ref = Database.database().reference()
      let storage = Storage.storage().reference(forURL: "gs://myProject-3j45.appspot.com")
  
      let key = ref.child("posts").childByAutoId().key
      let imgRef = storage.child("posts").child(uid!).child("\(key).jpeg")
  
  
      let data = UIImageJPEGRepresentation(coverImageData!, 0.8)
      let uploadTask = imgRef.putData(data!, metadata: nil) { (metadata, Error) in
          if Error != nil {
              print(Error?.localizedDescription as Any)
              return
          }
          imgRef.downloadURL { (url, err) in
              if let url = url {
                  let feed = ["pathToImage" : url.absoluteString ,
                              "likes" : 0 ,
                              "creator" : Auth.auth().currentUser?.displayName as Any,
                              "description" : describeData ,
                              "content" : contentData ,
                      ] as [String : Any]
                  let postFeed = ["\(key)" : feed]
                  ref.child("posts").updateChildValues(postFeed)
                  self.dismiss(animated: true, completion: nil)
              }
          }
      }
      uploadTask.resume()
      print(imageUploaded)
  
  
      for _ in images {
          if imageUploaded != imageToUpload {
  
              // for multiple images upload process 
              let mainKey = ref.child(key).childByAutoId().childByAutoId().key
              let mainImageRef = storage.child("posts").child(uid!).child("\(mainKey).jpeg")
  
              let mainData = UIImageJPEGRepresentation(images.first!, 0.7)
              let mainUploadTask = mainImageRef.putData(mainData!, metadata: nil) { (metadata, Error) in
                  if Error != nil {
                      print(Error?.localizedDescription as Any)
                      return
                  }
                  mainImageRef.downloadURL { (mainUrl, err) in
                      if let url = mainUrl {
                          let feeder = ["url" : url.absoluteString ] as [String : Any]
                          let mainImgUrls = ["\(key)" : feeder]
                          ref.child("posts").updateChildValues(mainImgUrls)
                          self.dismiss(animated: true, completion: nil)
                      }
                  }
              }
              mainUploadTask.resume()
              imageUploaded += 1
              images.removeFirst()
              print(imageUploaded)
          } else if imageUploaded == imageToUpload {
              print(imageUploaded)
              return
          }
  </code></pre>