Firebase Storage-How to delete file from storage with node.js?

后端 未结 4 1963
無奈伤痛
無奈伤痛 2020-12-21 18:23

I want to delete a folder in firebase storage with node js because this is a firebase function.

For example :

storageRef.child(child1).child(child2)         


        
4条回答
  •  执念已碎
    2020-12-21 18:42

    This might be late but at least on Web (so basically what you need), there is new API to delete the whole folder.

    I tested deleting a folder with 2 pictures inside and it works. I then tried a folder-A with contents: folder-B + picture-A. Folder-B also has a picture-B inside; it still deleted folder-A with all of its contents.

    Solution:

    const bucket = admin.storage().bucket();
    
    return bucket.deleteFiles({
      prefix: `posts/${postId}`
    );
    

    I couldn't find this on the official documentation (perhaps is really new API) but really cool article where I found the solution: Automatically delete your Firebase Storage Files from Firestore with Cloud Functions for Firebase

提交回复
热议问题