我已经存储了一些图像Firebase
,当我尝试下载它们时,我收到以下错误:E/StorageException: StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403
. 我也在使用谷歌身份验证。
这是我上传图片的方式:
StorageReference storageReference = firebaseStorage.getReferenceFromUrl("gs://appname-e2a32.appspot.com").child("hImage");
UploadTask uploadTask = storageReference.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getBaseContext(), exception.getMessage(), Toast.LENGTH_SHORT).show();
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl();
savingHelpRequest.dismiss();
Toast.makeText(getBaseContext(), "image uploaded", Toast.LENGTH_SHORT).show();
}
});
这是我尝试下载它的方式:
FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
storageReference = firebaseStorage.getReferenceFromUrl("gs://appname-e2a32.appspot.com").child("hImage");
storageReference.getBytes(Long.MAX_VALUE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
// Use the bytes to display the image
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
bytes = baoStream.toByteArray();
bmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
Toast.makeText(getBaseContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
}
});
以下是安全规则:
service firebase.storage {
match /b/appname-e2a32.appspot.com/o {
match /{allPaths=**} {
allow read, write;
}
}
}
请让我知道如何摆脱此错误并成功下载图像?