从firebase存储中删除图像

xyhw6mcr  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(134)

有时我上传图像从我的应用程序到firebase存储,我把URL在firebase firestore,有时我把URL手动从随机链接在firebase firestore,这是它不在我的存储,所以当我想删除项目在firestore它只删除,如果图像在我的存储

deleteItem(id) async {
    await FirebaseFirestore.instance.collection('sss').doc(id).delete();
    setState(() {});
  }

  deleteimage(url) async {
     await FirebaseStorage.instance.refFromURL(url).delete();
    setState(() {});
  }

Future<void> deletefun(images) async {
    for (int i = 0; i < images.length; i++) {
      var imageUrl = await deleteimage(images[i]);
    }
  }

和要删除按钮的代码

ElevatedButton(
 onPressed: () async {
                                                  
   if (data['imgurl'].isNotEmpty) {
      await deletefun(
 data['imgurl']); }            
await deleteItem(data.id);                                                                                                    
},
 child: const Text('delete'),
),}
cs7cruho

cs7cruho1#

floatingActionButton: FloatingActionButton(onPressed: ()async{
 FirebaseStorage ref = FirebaseStorage.instance;
        var file = await ref.ref('CoverImages/1657860002431.jpg');
        await file.delete().then((value) => print("File Deleted Successfully"));
      },),

相关问题