title: How to make function return parameter after firebase image upload?
body: <pre><code>fun profileSet(profile: MyProfileModel, chooseUri: Uri): Task&lt;DocumentReference&gt; {
  
      profile.registration_date = Timestamp.now()
  
      if (chooseUri != null) {
          val ref = storage.child(&quot;user_photo/${UUID.randomUUID()}&quot;)
          ref.putFile(chooseUri).continueWithTask { task -&gt;
              if (!task.isSuccessful) {
                  task.exception?.let {
                      throw it
                  }
              }
  
              ref.downloadUrl
          }.addOnCompleteListener{
              task-&gt;
              if (task.isSuccessful)
                  profile.profile_photo=task.result.toString()
          }
  
      }
  
      return database.collection(&quot;users&quot;).add(profile)
  
  }
  </code></pre>
  <p>In the code above, I upload a firebase image and after uploading it, I take the url of the image and save it to my model. I also save this model to the database, but here the method database.collection returns without loading the image and I can never save the image url. How can I do?</p>