taskSnapshot.downloadUrl.toString() dont work in Kotlin
taskSnapshot.downloadUrl.toString() dont work in Kotlin
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 :
DownloadURL = taskSnapshot.downloadUrl.toString()
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.
ImageRef
val
I inserted an image with a code sample and println. I think it has something to do with the firebase-storage version.
– MSilva
2 days ago
2 Answers
2
The reason is that the getDownloadUrl()
method does not return a URL or a String, it returns a Task<URI>
based on this documentation.
getDownloadUrl()
Task<URI>
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.
getResult()
.toString()
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
2 days ago
I got it by taking the result, but in a syntax as I posted it. Thank you.
– MSilva
yesterday
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 ())
}
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
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 aval
?– JRomero
2 days ago