0

I am having a problem getting the url of my image in firebase storage. Basically, each time the url is something like -

com.google.android.gms.tasks.zzu@899c8a

Yes I know people had the same problem yet I couldn't fix it with the answers they approved. I tried the following -

String upload = sRef.child("users/"+uid+"/"+SetModule+"/note-"+randomString).getDownloadUrl().toString();
String upload = taskSnapshot.getMetaData().getDownloadUrl().toString();
String upload = taskSnapshot.getStorage().toString();

but without any success.

I know that getMetaData is deprecated and I should use getStorage but it still didn't work. Uploading to the storage works perfectly.

I am using com.google.firebase:firebase-storage:16.0.1

Below is my code -

                final String randomString = getRandomString(6);
                StorageReference storageReference = sRef.child("users/"+uid+"/"+SetModule+"/note-"+randomString);
                storageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                        String upload = sRef.child("users/"+uid+"/"+SetModule+"/note-"+randomString).getDownloadUrl().toString();
                        myRef.child("users").child(uid).child("modules").child(SetModule).child("note-"+randomString).setValue(upload);

                        Log.d("MyTag","Upload Success");
                    }
                });
KeDeN
  • 105
  • 11
  • 1
    getDownloadUrl returns an asynchronous task, not a String. – Doug Stevenson Apr 20 '19 at 17:31
  • 1
    I'm not an Android or Firebase developer, but it looks to me like `getDownloadUrl` returns a `Task` rather than a `Uri`, so you'd need to get the result of that. – Jon Skeet Apr 20 '19 at 17:31
  • @JonSkeet thank you for advice, I got the result of the getDownloadUrl and everything works fine now. You can leave it as an answer and I'll approve it :) – KeDeN Apr 20 '19 at 17:48

0 Answers0