您可以帮助从Firebase存储中删除图像吗?字符串deleteImage
包含图片在Firebase存储空间中的完整网址。
我的代码如下,但它不会删除图像:
StorageReference deleteFile = storageReference.child(deleteImage);
deleteFile.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(EditProfile.this, "Previous Image Deleted", Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:22)
您需要使用此方法调用:
StorageReference photoRef = mFirebaseStorage.getReferenceFromUrl(mImageUrl);
然后按原样删除:
photoRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// File deleted successfully
Log.d(TAG, "onSuccess: deleted file");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
Log.d(TAG, "onFailure: did not delete file");
}
});
答案 1 :(得分:0)
使用功能getReferenceFromUrl(URL)
FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
StorageReference storageReference = firebaseStorage.getReferenceFrenter code hereomUrl(pd.getUrl());
storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e("Picture","#deleted");
}
});