0

I have made a function in javascript via node js which takes care that when a document is deleted, it deletes the folder associated to it. But there's something wrong can anyone help me out. In my storage i have a main folder with name 'Memories' and then sub-directories with userId as the name and then inside them are the pictures posted by the user. So i want to delete the sub-directory associated with the user.

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
admin.initializeApp();
    
exports.onDeleteAccount = functions.region('asia-south1').firestore
      .document("/users/{userId}")
      .onDelete(async (snapshot, context) => {

        const userId = context.params.userId;

        storage.bucket('firebasePrjectId.appspot.com').file('Moments').file(userId).delete();
      });
  • 1
    Possible duplicate. See the answer posted answered Apr 2 at 18:22 by coolcool https://stackoverflow.com/questions/37749647/firebasestorage-how-to-delete-directory – Cleanbeans Nov 17 '20 at 09:39
  • Hey @Deepak `gcs.bucket(functions.config().firebase.storageBucket);` This is not in your code above. Are you running this locally and getting this error? – Cleanbeans Nov 17 '20 at 13:07
  • Thanks a lot bro it worked. Actually i was making call on bucket before admin.initialiseApp(). –  Nov 17 '20 at 13:13

0 Answers0