1

I am trying to delete a file with a URL from FirebaseStorage and while deleting it I am receiving this error.

Code

Future<void> deleteImage(String imageUrl) async {
    
    try {
      await FirebaseStorage.instance.ref(imageUrl).delete();
    } catch (e) { 
       debugPrint('Error : $e'); 
    }

}

I want to delete the image with given imageUrl. How can I achieve this..?

My imageUrl sample: https://firebasestorage.googleapis.com/v0/b/flutter-8bd46.appspot.com/o/post_394be2ba-592c-45c9-9dab-fd72920f7afe.jpg?alt=media&token=98801435-192b-4ec1-b8e1-e73bac0bb9eb

7
  • Can you log and show what imageUrl look like? Commented Jun 24, 2021 at 19:14
  • @Dharmaraj Sure I have edited it in the problem. Commented Jun 24, 2021 at 19:17
  • You should pass only "post_394be2ba-592c-45c9-9dab-fd72920f7afe.jpg" in the .ref() can you try that? Commented Jun 24, 2021 at 19:18
  • Maybe .refFromURL(imageUrl) would work Commented Jun 24, 2021 at 19:25
  • @Dharmaraj Thanks bro, Its Working..!! Commented Jun 24, 2021 at 19:47

1 Answer 1

2

As the error suggests, you don't need to pass the domain or the complete URL. Only the path to that file is required. For example:

/images/images.png

Alternatively you can use refFromURL(url) to use the URL instead of path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.