title: Why aren't my Firebase Storage URLs uploading to Google Cloud Firestore?
body: <p>I am trying to allow users to upload a profile photo to Firebase Storage. The image gets uploaded during the sign up process of my app. The image is being uploaded to Firebase Storage properly, however, the download URL is not uploading to Google Cloud Firestore.</p>
  
  <p>I've already tried to change my variable <code>downloadURL</code> of type <code>String</code> to hold an empty <code>String</code>. This did not change the result.</p>
  
  <p>Here is the code to upload the profile photo to Firebase Storage:</p>
  
  <pre><code>func uploadProfilePic() -&gt; String {
       guard let imageData = profilePic?.jpegData(compressionQuality: 0.75) else {
           print("Unable to get image data.")
           return ""
       }
  
       let imageID = UUID().uuidString
       let profilePhotosRef = Storage.storage().reference().child("profilePhotos/\(imageID).jpg")
  
       let uploadMetadata = StorageMetadata()
       uploadMetadata.contentType = "image/jpeg"
  
       var downloadURL = String()
       profilePhotosRef.putData(imageData, metadata: uploadMetadata) { (downloadMetadata, err) in
           if let err = err {
               self.showAlertWithOK(title: "An Error Occurred", message: "There was an error uploading your profile photo. Try again later in Hostend settings.")
               print("An error occurred: \(err.localizedDescription)")
           }
  
           profilePhotosRef.downloadURL { (url, err) in
               if let url = url {
                   downloadURL = url.absoluteString
               }
           }
       }
  
       return downloadURL
  }
  </code></pre>
  
  <p>Here is the code for uploading the profile photo download URL to Cloud Firestore:</p>
  
  <pre><code>db.collection("users").document(uid).setData(["profile_pic_url": uploadProfilePic(), "name": name, "phone_number": phoneNumber, "fcm_token": token, "timestamp": Date()])
  </code></pre>
  
  <p>The <code>uploadProfilePic()</code> method returns a <code>String</code>.</p>
  
  <p>I expected the download URL of the image to be uploaded to Firestore under "profile_pic_url," but that did not happen. Instead, it is just an empty <code>String</code> even though the image had been successfully to Firebase Storage.</p>