Can you help delete an image from Firebase Storage. String deleteImage
holds the full url of where the image is located in the Firebase storage.
My code is as follows, but it does not delete the image:
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();
}
});
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");
}
});