Firebase how to get Image Url from firebase storage?

Rjz Satvara picture Rjz Satvara · Oct 21, 2016 · Viewed 82.6k times · Source

Right now i am fetching image from Storage of Firebase by using below code :

mStoreRef.child("photos/" + model.getBase64Image())
          .getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            // Got the download URL for 'photos/profile.png'

                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception exception) {
                            // Handle any errors
                            Toast.makeTextthis, "image not dowloaded", Toast.LENGTH_SHORT).show();
                        }
                    });

How to get this URL ?

it is Possible to get this URL which is shown in Image..???

Answer

Shamik Chodankar picture Shamik Chodankar · Feb 24, 2017

Follow this link -https://firebase.google.com/docs/storage/android/download-files#download_data_via_url

    storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            // Got the download URL for 'users/me/profile.png'
            Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
            generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
        }
    });