1

I am trying to use the Firebase storage from Android app. In the beginning all worked fine. Now I am getting response:

 {  
     "error": {
        "code": 400,
        "message": "Permission denied. Could not access bucket adiglehard.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."  
      }
  }

Uploading code is:

storage = FirebaseStorage.getInstance("gs://adiglehard.appspot.com/");
Uri file = Uri.fromFile(new File(mFile.getAbsolutePath()));
StorageReference storageRef = storage.getReference();
StorageReference riversRef = storageRef.child("images/" + file.getLastPathSegment());
uploadTask = riversRef.putFile(file);

// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
  @Override
  public void onFailure(@NonNull Exception exception) {
      // Handle unsuccessful uploads
      showToast("error!!!!");
      exception.printStackTrace();

  }
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
  @Override
  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
      showToast("success!!!!");
  }
});

The Firestore rules are:

// Anyone can read or write to the bucket, even non-users of your app.
// Because it is shared with Google App Engine, this will also make
// files uploaded via GAE public.
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69
  • Possible duplicate of [Firebase storage security rules 400 error issue "Permission denied. Could not access bucket xxxxx-\*\*\*\*.appspot.com"](https://stackoverflow.com/questions/50292353/firebase-storage-security-rules-400-error-issue-permission-denied-could-not-ac) – goblin May 16 '18 at 20:45

1 Answers1

3

I think this is due to a missing permission in your Google cloud console. You need to check whether you have firebase-storage@system.gserviceaccount.com as Storage Admin. If you don't have one, then add it. It fixed the issue in my case.

P.S. : There are various reports for a permissions issue with Firebase Storage. The Firebase Storage service account is being errantly removed from buckets, which causes requests to give errors recently. Here's the link.

Steps:

Add the missing permission. You can also add the missing permission in the IAM & Admin if you want.

Masoom Badi
  • 986
  • 9
  • 18
  • 1
    Cheers man, Happy to help.. The issue is not fixed yet, so if you encounter any instance of that problem you add the permission manually. It is also mentioned in link i gave for the issue. – Masoom Badi May 16 '18 at 11:33