Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a social media app where users can upload there pic. I want to add a delete option for the users in the app. I want the users to delete their pic from Firebase cloud storage whenever needed. Here is my code

val firebase_url = contentDTOs[p1].imageUrl
            val storageRef =
                firebase_url?.let { it1 ->
                    FirebaseFirestore.getInstance().collection("images").document(
                        it1
                    )
                }

             storageRef?.delete()?.addOnSuccessListener {
                // File deleted successfully
                Toast.makeText(context , "Deleted",Toast.LENGTH_SHORT).show()

            }?.addOnFailureListener {
                // Uh-oh, an error occurred!
                Toast.makeText(context , "cannot delete",Toast.LENGTH_SHORT).show()
            }

            return@setOnLongClickListener true


But whenever I try to delete any image it returns me an error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.videoapp, PID: 20522
    java.lang.IllegalArgumentException: Invalid path (https://firebasestorage.googleapis.com/v0/b/video-app-af9bf.appspot.com/o/images%2FIMAGE_20201023_144632_.png?alt=media&token=9cd9d400-49ed-4f73-81b3-baa7668a8430). Paths must not contain // in them.


What I have tried:

I am trying to delete image from firebase
Posted
Updated 23-Oct-20 3:24am
v2
Comments
David Crow 23-Oct-20 8:49am    
"Paths must not contain // in them."

Is this a question or a statement?
Member 14883729 23-Oct-20 9:14am    
It's a statement which I am getting whenever I try to delete any image
David Crow 23-Oct-20 9:22am    
It looks as though you may be confusing a file path with a URL.

1 solution

Look at the documentation for help: Delete Files on Web  |  Firebase[^]
 
Share this answer
 
Comments
Member 14883729 23-Oct-20 9:48am    
I have already read it and tried it but the result is same
Richard MacCutchan 23-Oct-20 10:08am    
We cannot see anything more than you have shown us above, so we cannot guess what you are doing wrong. You will need to use your debugger to gather more detailed information.
ZurdoDev 23-Oct-20 15:00pm    
From that link:
// Create a reference to the file to delete
var desertRef = storageRef.child('images/desert.jpg');

But your link has the full url. You need to follow the documentation.
ZurdoDev 23-Oct-20 15:00pm    
+5. First google result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900