title: How to retrieve the download URL of an image from Firebase Storage?
body: <p>I am watching an old tutorial about Firebase Storage. The <code>getDownloadUrl()</code> method from <code>UploadTask.TaskSnapshot</code> is no longer existent, and the <a href="https://firebase.google.com/docs/storage/android/upload-files#get_a_download_url" rel="nofollow noreferrer">documentation</a> fails to be clear to me.</p>
  
  <p>What I've implemented so far is the upload process and I can confirm it works, but getting the URL is a pain and I can't make the way they explain how to do it because:</p>
  
  <p>1) Creating a <code>Task&lt;Uri&gt; urlTask = uploadTask.add[...]()</code> will result in the following error on the IDE:</p>
  
  <p><a href="https://i.stack.imgur.com/McvGA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/McvGA.png" alt="enter image description here"></a></p>
  
  <p>I don't understand because it is specified in the docs.</p>
  
  <p>2) Using <code>reference.getDownloadUrl()</code> will display a different URL compared to what is shown on the console when seeing the details of the uploaded image. The download URL the console shows is</p>
  
  <blockquote>
    <p><a href="https://firebasestorage.googleapis.com/v0/b/chatroom-e44e6.appspot.com/o/chat_photos%2F73185640?alt=media&amp;token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" rel="nofollow noreferrer">https://firebasestorage.googleapis.com/v0/b/chatroom-e44e6.appspot.com/o/chat_photos%2F73185640?alt=media&amp;token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</a></p>
  </blockquote>
  
  <p>while logging will show</p>
  
  <blockquote>
    <p>com.google.android.gms.tasks.xxx@xxxxxxx</p>
  </blockquote>
  
  <p>My full code at the moment:</p>
  
  <pre><code>if (requestCode == RC_PHOTO_PICKER) {
      if (data != null) {
          Toast.makeText(MainActivity.this, "Uploading...", Toast.LENGTH_SHORT).show();
  
          Uri file = data.getData();
          final StorageReference reference = mPhotoStorageReference.child(file.getLastPathSegment());
          UploadTask upload = reference.putFile(file);
  
          upload.addOnFailureListener(this, new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  Toast.makeText(MainActivity.this, "Image could not be uploaded: " + e.getMessage(), Toast.LENGTH_LONG).show();
              }
          }).addOnCompleteListener(this, new OnCompleteListener&lt;UploadTask.TaskSnapshot&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;UploadTask.TaskSnapshot&gt; task) {
                  ChatroomMessage message = new ChatroomMessage(null, mUsername, reference.getDownloadUrl().toString()); // &lt;- com.google.android.gms.tasks.xxx@xxxxxxx
                  mMessagesDatabaseReference.push().setValue(message);
                  Toast.makeText(MainActivity.this, "Image uploaded!", Toast.LENGTH_SHORT).show();
              }
          });
      }
  }
  </code></pre>
  
  <p>My app already has Firebase UI implemented to handle login operations, and the rules are </p>
  
  <pre><code>service firebase.storage {
    match /b/{bucket}/o {
      match /{allPaths=**} {
        allow read, write: if request.auth != null;
      }
    }
  }
  </code></pre>