In my android app i am using Firebase Storage to save images i have set security rules to null then too i am not able to upload images and getting error. Below are my error ,security rules and android code.Please let me know what i did wrong in code.
Logcat error : StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403
Security rules:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth == null;
}
}
}
Java code:
galleryFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(SetAvatar.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},1);
}
else{
Intent i = new Intent(Intent.ACTION_PICK);
i.setType("image/*");
startActivityForResult(i,GALLERY_INTENT);
}
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
uri = data.getData();
cv.setImageURI(uri);
final StorageReference filepath = sRef.child("Profile
Images").child(uri.getLastPathSegment());
UploadTask uploadTask = filepath.putFile(uri);
uploadTask.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(SetAvatar.this, "Upload
successful",Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(SetAvatar.this, "Upload Failed -> " + e,
Toast.LENGTH_SHORT).show();
}
});
}
}
Thanks
request.auth == true
then try again – user9025311