Home > Blockchain >  403 error on downloadUrl (Kotlin) in Firebase Storage
403 error on downloadUrl (Kotlin) in Firebase Storage

Time:02-05

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.

This too:

E/StorageException: StorageException has occurred. The user does not have permission to access this object. Code: -13021 HttpResult: 403 E/StorageException: { "error": { "code": 403, "message": "Permission denied." }} java.io.IOException: { "error": { "code": 403, "message": "Permission denied." }}

When this code is hit in my android app:

val urlTask = uploadTask?.continueWithTask { task ->
 if (!task.isSuccessful) {

    Toast.makeText(context, "Upload to Cloud Failed!", Toast.LENGTH_SHORT).show()

task.exception?.let {

     throw it
}

} imagesRef?.downloadUrl.....ERROR IS GENERATED HERE...

Started when I turned on email/password authorization and turned off the anonymous sign in, however, I turned the anonymous sign-in back on and make sure auth is not null before starting the upload.

        val auth = Firebase.auth
        val user = auth.currentUser

ALSO, IT SAVES THE UPLOADED IMAGES TO STORAGE NO PROBLEM...but won't download the Url.

Here are the rules in place for my Firebase Storage:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /images/{imageId} {

      allow write: if request.auth != null;
      
      allow read: if request.auth != null;
    }
  }
}

I have not been able to find an answer to why it will upload but not download the URL.

CodePudding user response:

The problem in your code is present due to the fact that your user is not authenticated when you try to read the file from Cloud Storage. To be able to read a file, you should always make sure your use is authenticated in Firebase. That being said, please check the FirebaseUser object against nullity before performing Cloud Storage operations.

  • Related