-2

How can i delete this photo using Kotlin? Can you please help me solving this problem?

Kotlin

 private fun uploadPhoto() {
        if (selectedPhotoUri == null) return
        val filename = UUID.randomUUID().toString()
        val ref = FirebaseStorage.getInstance().getReference("/Users/$filename")
        ref.putFile(selectedPhotoUri!!)
                .addOnSuccessListener {
                    ref.downloadUrl.addOnSuccessListener {
                        url = it.toString()
                        store(url!!)
                    }
                }
                .addOnFailureListener {
                    Toast.makeText(this, "", Toast.LENGTH_LONG).show()

                }
    }
Alperen Kantarcı
  • 1,038
  • 9
  • 27
  • What did you try so far? at what point are you stuck. Please try to provide more information so more people may help you. 'Editor Review' – Zeeshan Adil Sep 14 '18 at 05:43

1 Answers1

0

First you need to get the reference for the photo that you will remove. You can use the url of the image or another method to access the reference of the image. The code below is directly from the Firebase Documentation.

StorageReference desertRef = mFirebaseStorage.getReferenceFromUrl(mImageUrl);

// Delete the file
desertRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
    @Override
    public void onSuccess(Void aVoid) {
        // File deleted successfully
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Uh-oh, an error occurred!
    }
});
Alperen Kantarcı
  • 1,038
  • 9
  • 27