0

I am working on Android Studio and using Firebase Storage, I could upload the images I want, but couldn't get the download url.

I used this:

askSnapshot.getMetadata().getReference().getDownloadUrl().toString();

and this:

filepath.getDownloadUrl().toString();

and the result was the same

it shows me some thing like this:

com.google.android.gms.tasks.zzu@f7d5815

my upload code:

FirebaseStorage storage; StorageReference storageReference;

storage = FirebaseStorage.getInstance(); storageReference = storage.getReference(); final StorageReference filepath = storageReference.child("images").child( "test.jpg");

       filepath.putFile(selectedImage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
           @Override
           public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
               bigImageEncoded=filepath.getDownloadUrl().toString();
               thumbImageEncoded=taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();

               Log.d("download_url",bigImageEncoded);


           }
       }).addOnFailureListener(new OnFailureListener() {
           @Override
           public void onFailure(@NonNull Exception e) {
                  Log.d("erorr",e.getMessage());
           }
       });

Anyone can help?!! Thanks

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
aboahmad
  • 11
  • 1
  • 6

2 Answers2

3

To solve this, I recommend that upon uploading any file, store the download URL to a database like Firebase Realtime Database or the new Cloud Firestore so it can be used later.

Please see below a simple example of getting the download URL.

storageRef.child("YourFolderName").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        // Got the download URL for "YourFolderName/YourFile.pdf"
        // Add it to your database
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
1

You need to listener to this event

filepath.getDownloadUrl().addOnSuccessListener(...{...})

and you will get uri in callback