How to solve Firebase Storage: Error getting a token

Viewed 174

I am trying to upload files to my Firebase Storage using Kotlin, but I am getting this error:

E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

I want to upload all files inside a directory, so I walk this directory and upload each file inside it

This is my code:

dir.walk().forEach {
            if (!it.isDirectory){
                var childRef = storageRef.child("user_downloads/${it.name}")
                var fileuri = Uri.fromFile(it)
                var uploadTask = childRef.putFile(fileuri)

                val urlTask = uploadTask.continueWithTask { task ->
                    if (!task.isSuccessful) {
                        task.exception?.let {
                            throw it
                        }
                    }
                    childRef.downloadUrl
                }.addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        val downloadUri = task.result
                        urlArray.add(downloadUri.toString())
                    } else {
                        //do nothing
                    }
                }
            }
        }

I already declared the storage ref:

var storage = FirebaseStorage.getInstance("gs://fir-c7344.appspot.com/")
var storageRef = storage.reference

And this is my firebase rules:

service firebase.storage {
  match /b/fir-c7344.appspot.com/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

I don't want to sign in to upload the files, so what can I do?

0 Answers
Related