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?