【问题标题】:How to delete image from Firebase storage by url?如何通过 url 从 Firebase 存储中删除图像?
【发布时间】:2020-10-22 20:13:57
【问题描述】:

如何通过 url 从 Firebase 存储中删除图像? 当我从集合中删除项目(类别)时,图像仍保留在存储中。

接口类别:

    export interface ICategory {
        readonly id     : string
        name            : string
        image           : string 
    }

删除函数

    export const removeCategoryFB = (id: string, setCategories: any) => {
      firestore()
        .collection("categories")
        .doc(id)
        .delete()
        .then(() => {
          getCategoriesFB(setCategories);
        })
        .catch((err) => {
          alert(err);
        });
    };

【问题讨论】:

  • firestore()处的数据库要参考

标签: typescript firebase google-cloud-firestore


【解决方案1】:

我解决了这个问题

refFromURL(URL)

示例代码

  firestore()
    .collection('categories')
    .doc(id)
    .get()
    .then((snapshot) => {
      storage()
        .refFromURL(snapshot.data().image.url)
        .delete()
    })

【讨论】:

    【解决方案2】:

    您需要获取存储参考,然后您将提供文件存储路径以删除文件。

    deleteChatFiles(filePath) {
        const spaceRef = firebase
          .storage()
          .ref()
          .child(filePath);
        spaceRef.delete();
      } 
    
    this.deleteFile('files/1579283129986-vMglgpHwT6c06RSmAiuYP6Hk2sz1.png');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-24
      • 2017-08-13
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 2018-05-02
      • 1970-01-01
      相关资源
      最近更新 更多