title: Retrieving image from Firebase Storage
body: <p>I know this is a discussed topic, but here I am, after all other solutions I've found did not solve my problem. I saved multiple images in Firebase Storage and now I want to get one of them and put it into an <code>ImageView</code> on an <code>AlertDialog</code> (or another Activity).</p>
  <p>I've read about <code>Glide</code> solution, but it doesn't work for me. Gilde:</p>
  <pre><code>Glide.with(ViewScenesSG.this) //ViewScenesSG is the Activity
                  .load(reference) //the storage reference
                  .into(imageView); //my imageView
  </code></pre>
  <p>Dependencies for Glide (I've tried with multiple versions and 4.8.0 is the only one that doesn't give me Build error):</p>
  <pre><code>implementation 'com.github.bumptech.glide:glide:4.8.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
  annotationProcessor 'androidx.annotation:annotation:1.1.0'
  </code></pre>
  <p>I've also read about the <code>.using(new FirebaseImageLoader())</code> method, I've implemented the <a href="http://github.com/firebase/FirebaseUI-Android/blob/master/storage/src/main/java/com/firebase/ui/storage/images/FirebaseImageLoader.java" rel="nofollow noreferrer">FirebaseImageLoader()</a>, but the <code>using()</code> method is not found =&gt; build error. I believe it's been removed.</p>
  <p>The second version I've tried is this one (found in another question <a href="https://stackoverflow.com/a/50162491/10695253">here</a>):</p>
  <pre><code>final long ONE_MEGABYTE = 1024 * 1024;
         reference.getBytes(ONE_MEGABYTE)
             .addOnSuccessListener(new OnSuccessListener&lt;byte[]&gt;() {
                 @Override
                 public void onSuccess(byte[] bytes) {
                     Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                     DisplayMetrics dm = new DisplayMetrics();
                     getWindowManager().getDefaultDisplay().getMetrics(dm);
                     
                     imageView.setMinimumHeight(dm.heightPixels);
                     imageView.setMinimumWidth(dm.widthPixels);
                     imageView.setImageBitmap(bm);
                 }
             }).addOnFailureListener(new OnFailureListener() {
             @Override
             public void onFailure(@NonNull Exception exception) {
                 Toast.makeText(ViewScenesSG.this, &quot;Couldn't retrieve image.&quot;, Toast.LENGTH_SHORT).show();
             }
         });
  </code></pre>
  <p>But every time it goes on the Failure listener. Therefore, my imageView always remains empty.</p>
  <p>In my logcat I observed this error:</p>
  <pre><code>E/StorageException: Could not open resulting stream.
      java.io.IOException: Could not open resulting stream.
          at com.google.firebase.storage.StreamDownloadTask.createDownloadStream(com.google.firebase:firebase-storage@@19.1.1:145)
          at com.google.firebase.storage.StreamDownloadTask.access$000(com.google.firebase:firebase-storage@@19.1.1:36)
          at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:167)
          at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:164)
          at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.ensureStream(com.google.firebase:firebase-storage@@19.1.1:325)
          at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.access$100(com.google.firebase:firebase-storage@@19.1.1:262)
          at com.google.firebase.storage.StreamDownloadTask.run(com.google.firebase:firebase-storage@@19.1.1:175)
          at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
          at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
          at java.lang.Thread.run(Thread.java:764)
  E/StorageException: StorageException has occurred.
      Object does not exist at location.
       Code: -13010 HttpResult: 404
  </code></pre>
  <p>But the image is there, in the Storage, and the reference points directly to it:</p>
  <pre><code>storageRef = storage.getReference(&quot;photos&quot;).child(title); //for all images in the current folder named with the 'title' attribute
  StorageReference reference = storageRef.child(imageName); //for the image I want to retrieve
  </code></pre>
  <p>What am I missing?</p>
  <p><strong>EDIT:</strong> Using the suggestion in the coments, I tried with:</p>
  <pre><code>reference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
              @Override
              public void onSuccess(Uri uri) {
                  Glide.with(ViewScenesSG.this)
                          .load(uri.toString())
                          .into(imageView);
              }
          }).addOnFailureListener(new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  Toast.makeText(ViewScenesSG.this, &quot;Retrieving image failed&quot;,
                          Toast.LENGTH_SHORT).show();
              }
          });
  </code></pre>
  <p>but this time I get the error:</p>
  <pre><code>E/StorageException: {  &quot;error&quot;: {    &quot;code&quot;: 404,    &quot;message&quot;: &quot;Not Found.  Could not get object&quot;,    &quot;status&quot;: &quot;GET_OBJECT&quot;  }}
      java.io.IOException: {  &quot;error&quot;: {    &quot;code&quot;: 404,    &quot;message&quot;: &quot;Not Found.  Could not get object&quot;,    &quot;status&quot;: &quot;GET_OBJECT&quot;  }}
          at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@19.1.1:433)
          at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@19.1.1:450)
          at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@19.1.1:441)
          at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:272)
          at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:286)
          at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:70)
          at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:62)
          at com.google.firebase.storage.GetDownloadUrlTask.run(com.google.firebase:firebase-storage@@19.1.1:76)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
          at java.lang.Thread.run(Thread.java:764)
  </code></pre>