0

I guess Kotlin made some changes about downloadURI method.

There is another question already asked before but it's java code, I couldn't convert to Kotlin.

How to use getdownloadurl in recent versions?

So I'm trying to using new one like below,

var storageRef = FirebaseStorage.getInstance().getReference()
    val ref = storageRef.child("uploads/profil.jpg")

    ref.downloadUrl.addOnSuccessListener {
        val temp = it.path
    }

From the debug, I can see the download link with "it.uriString" on "temp" variable line. But I don't know how to get this URL from there?

Thanks.

sleepy
  • 167
  • 1
  • 2
  • 9
  • Have you followed this [link](https://firebase.google.com/docs/storage/android/download-files#download_data_via_url)? – Abhishek Dec 11 '19 at 10:08
  • Yes, but I couldn't solve how to get download URL inside addOnSuccessListener – sleepy Dec 11 '19 at 10:17
  • here is helper class for Firebase storage https://github.com/AtifAbbAsi19/Clean-architecture-android/tree/master/app/src/main/java/com/droid/clean_architecture_android_tutorial/network/firebase/storage – Atif AbbAsi Dec 11 '19 at 13:25

1 Answers1

0

Have you checked this link

val ref = storageRef.child("images/mountains.jpg")
uploadTask = ref.putFile(file)

val urlTask = uploadTask.continueWithTask { task ->
    if (!task.isSuccessful) {
        task.exception?.let {
            throw it
        }
    }
    ref.downloadUrl
}.addOnCompleteListener { task ->
    if (task.isSuccessful) {
        val downloadUri = task.result
    } else {
        // Handle failures
        // ...
    }
}

This snippet will help you hopefully.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437