1

Code Img

I'm trying to follow a tutorial but the part that teaches the value of DownloadURL = taskSnapshot.downloadUrl.toString() does not work anymore. I tried to substitute some options like :

val DownloadURL = taskSnapshot.storage.downloadUrl.toString()

Or :

val DownloadURL = ImageRef.downloadUrl.toString()

But I only get print values such as :

com.google.android.gms.tasks.zzu@8a94cv2 and not a valid url.

2
  • Think we need a little bit more code. What is class is ImageRef since it seems like you don't follow common casing conventions and is probably a val?
    – JRomero
    Jun 29, 2018 at 5:14
  • I inserted an image with a code sample and println. I think it has something to do with the firebase-storage version.
    – MSilva
    Jun 29, 2018 at 5:43

3 Answers 3

2

You can use this after onSuccessListener.....

val downloadURL = taskSnapshot.getStorage().getDownloadUrl().toString()

Hope it helps.

0

The reason is that the getDownloadUrl() method does not return a URL or a String, it returns a Task<URI> based on this documentation.

If you would like to get the Uri itself, then you can use the getResult() to get the result and then do a .toString() on that.

2
  • I also did something like this before creating the topic. If I use: var url = taskSnapshot.result I get something like com.google.firebase.storage.UploadTask$TaskSnapshot@de56db
    – MSilva
    Jun 29, 2018 at 6:57
  • I got it by taking the result, but in a syntax as I posted it. Thank you.
    – MSilva
    Jun 30, 2018 at 6:59
0

I can not say exactly why it did not work with other syntaxes, but I got the result doing it this way: (Firebase implementation version: 16.0.1 / Kotlin)

My solution:

mReference.putFile (uri) .addOnFailureListener {
          // failure
       } .addOnSuccessListener () {taskSnapshot ->
          // success
             mReference.downloadUrl.addOnCompleteListener () {taskSnapshot ->

                 var url = taskSnapshot.result
                 println ("url =" + url.toString ())

             }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.