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();
}
});
Delete files from FirebaseUsing refFromURL() , get the image reference from Firebase Storage of the image that should be deleted. Then use . delete() to delete the image from Firebase. Finally, remove that URL from the allImages array.
To delete a file, first create a reference. to that file. Then call the delete() method on that reference.
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");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With