How to delete image from Firebase Storage?
You need to use this method call:
StorageReference photoRef = mFirebaseStorage.getReferenceFromUrl(mImageUrl);
Then delete as you were:
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");
}
});
Use the function getReferenceFromUrl(URL)
FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
StorageReference storageReference = firebaseStorage.getReferenceFromUrl(pd.getUrl());
storageReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e("Picture","#deleted");
}
});