0

i have checked available resources and yet either i get error or at best i get com.google.android.gms.tasks.zzu@5f9a842 as the uri

Following this latest google doc here, i still got the com.gms as url

here is my code

 val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg") val uploadTask = fileRef.putFile(imageUri!!) uploadTask.continueWith { if (!it.isSuccessful) { pd.dismiss() it.exception?.let { t -> throw t } } fileRef.downloadUrl }.addOnCompleteListener { if (it.isSuccessful) { val downloadUrl = it.result myUri = downloadUrl.toString() print("Task: ${downloadUrl}") ... 

Terminal: I/System.out: Task: com.google.android.gms.tasks.zzu@4298dc1(HTTPLog)-Static: isSBSettingEnabled false

9
  • 1
    The duplicate primarily talks about java, but the underlying issue is the same. downloadUrl returns a Task, not a URL. You have to deal with it asynchronously just like the Task returned from putFile. See also the documentation: firebase.google.com/docs/storage/android/… Commented Apr 5, 2020 at 23:23
  • what's the difference between OnCompleteListener and OnSuccesListener ? Commented Apr 5, 2020 at 23:28
  • Tried it, still didn't work...pls what is the best way to get the uri after uploading it...? Commented Apr 5, 2020 at 23:45
  • 1
    The way shown in the documentation. If you have made a new attempt using what you know already about Tasks (you already used one with putFile), please post a new question showing what you have that doesn't work the way you expect. Commented Apr 5, 2020 at 23:57
  • 2
    @FrankvanPuffelen My mistake. They're just logging the wrong thing. Commented Apr 6, 2020 at 2:45

3 Answers 3

0

You're logging the wrong value. Instead of this:

print("Task: ${downloadUrl}") 

Log this:

print("Task: ${downloadUrl.result.toString()}") 

Your downloadUrl variable is not correctly named. It's a Task, not a URL. It might be clearer like this:

val task = it.result val uri = task.result val uriAsString = uri.toString() 
Sign up to request clarification or add additional context in comments.

1 Comment

val uri = task.result gives this error :: java.lang.IllegalStateException: Task is not yet complete
0

Solved !!!

 val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg") val uploadTask = fileRef.putFile(imageUri!!) uploadTask.continueWith { if (!it.isSuccessful) { pd.dismiss() it.exception?.let { t -> throw t } } fileRef.downloadUrl }.addOnCompleteListener { if (it.isSuccessful) { val downloadUrl = it.result //Here returns a task.. myUri = downloadUrl.toString() print("Task: ${downloadUrl}") ... 

val downloadurl = it.result returns a Task

correct it by adding an addOnSuccessListener

so the correct code is

val uploadTask = fileRef.putFile(imageUri!!) uploadTask.continueWith { if (!it.isSuccessful) { pd.dismiss() it.exception?.let { t -> throw t } } fileRef.downloadUrl }.addOnCompleteListener { if (it.isSuccessful) { it.result!!.addOnSuccessListener{task -> myUri = task.toString() print("$myUri") ... } 

Comments

0

i sloved the problem you should make addOnSuccessListener return uri->unit not task

}.addOnCompleteListener { if (it.isSuccessful) { it.result!!.addOnSuccessListener{uri->unit -> myUri = task.toString() print("$myUri") ... } 

2 Comments

then myuri =uri.toString
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.