0

I have error like this :

java.io.IOException: { "error": { "code": 400, "message": "Permission denied. 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." }}

However, my storage rules here:

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

And I think my code's right but the error is still showing up, here is my code:

Calendar calendar=Calendar.getInstance();
               StorageReference mountainsRef = storageRef.child("image"+calendar.getTimeInMillis()+".png");
               // Get the data from an ImageView as bytes
               imgHinh.setDrawingCacheEnabled(true);
               imgHinh.buildDrawingCache();
               Bitmap bitmap = ((BitmapDrawable) imgHinh.getDrawable()).getBitmap();
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
               byte[] data = baos.toByteArray();

               UploadTask uploadTask = mountainsRef.putBytes(data);
               uploadTask.addOnFailureListener(new OnFailureListener() {
                   @Override
                   public void onFailure(@NonNull Exception exception) {
                       Toast.makeText(MainActivity.this, "Failed !", Toast.LENGTH_SHORT).show();
                   }
               }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                   @Override
                   public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                       Log.d("hivu", taskSnapshot.getUploadSessionUri()+"");
                       Toast.makeText(MainActivity.this, "Success !", Toast.LENGTH_SHORT).show();
                   }
               });

Please help me to solve this, I don't know where is the error coming from?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I linked a solution from a while back. If that doesn't solve the issue for you, can you [reach out to Firebase support](https://firebase.google.com/support/contact/troubleshooting/) for personalized help in troubleshooting? – Frank van Puffelen Nov 20 '21 at 15:49
  • I have tried your solution and it’s not working at all – Quốc Vũ Nov 20 '21 at 15:53
  • Sorry to hear that @QuốcVũ. In that case please reach out to Firebase support, so they can have a look. We're seen some similar cases recently, and a workaround there was to use another (gmail) account. But that of course shouldn't be the proper solution, so hopefully our support team can find the root cause of this. – Frank van Puffelen Nov 20 '21 at 16:01
  • I will reach out to Firebase support to see what is the root cause of this error. By the way, thanks you for some helps – Quốc Vũ Nov 20 '21 at 16:22
  • *firebaser here* If this was a project that you created in the past few days, you may have been affected by a bug in our project creation. If so, that problem has been fixed so that new projects won't be affected anymore. To fix your existing project, have a look at the steps here : https://stackoverflow.com/a/70060240 – Frank van Puffelen Nov 22 '21 at 02:24
  • Oh I see, my project suddenly work very well and that error does not show anymore – Quốc Vũ Nov 22 '21 at 03:15

1 Answers1

0

Most probably you need to update your Storage rules as given below -

service firebase.storage {
  match /b/luu-hinh-voi-firebase.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}
Anuj Raghuvanshi
  • 664
  • 1
  • 7
  • 24