I want to delete a Firebase Storage folder and all its contents using node.js / Firebase Admin SDK but I'm not able to.
A similar question was asked in the google group below about a year ago and I'm wondering if there is a solution now:
https://groups.google.com/forum/#!topic/firebase-talk/aG7GSR7kVtw
I am able to delete a single file using node.js example below:
https://mzmuse.com/blog/how-to-upload-to-firebase-storage-in-node
But I'm not able to delete a folder and all it's contents.
Any ideas? Am I missing something?
Here's the code I'm using
const keyFilename="path/to/my/private.json";
const projectId = "myprojectid";
const bucketName = `${projectId}.appspot.com`;
const gcs = require('@google-cloud/storage')({
projectId,
keyFilename
});
const bucket = gcs.bucket(bucketName);
THIS WORKS FINE - Deleting a single file
const deleteFile = 'users/user1/folder1/IMG_1.JPG'
const gcFile = bucket.file(deleteFile);
gcFile.delete((err,res)=>console.log(err||res));
THIS DOES NOT WORK - Deleting the folder and contents
const deleteFolder = 'users/user1/'
const gcFolder = bucket.file(deleteFolder);
gcFolder.delete((err,res)=>console.log(err||res));
--
THIS IS NOT A DUPE AS MARKED BY SOME MEMBERS
My question is specific to node.js and the answer given is for Java.
UPDATE
I found this a page in google cloud site where they show a way to delete all files under a directory (folder)
bucket.deleteFiles({
prefix: 'images/'
}, function(err) {
if (!err) {
// All files in the `images` directory have been deleted.
}
});
But I'm still not able to delete the folder itself