Flutter Error : [firebase_storage/unknown] location should not be a full URL

Flutter Error : [firebase_storage/unknown] location should not be a full URL

我正在尝试从 FirebaseStorage 中删除带有 URL 的文件,但在删除它时收到此错误。

代码

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

}

我想删除具有给定 imageUrl 的图像。我怎样才能做到这一点..?

我的 imageUrl 示例: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

正如错误提示的那样,您不需要传递域或完整的 URL。只需要该文件的路径。例如:

/images/images.png

或者您可以使用 refFromURL(url) 来使用 URL 而不是路径。