I can't find a way to delete all the files inside firebase storage that match a regular expression. I would like to use something like:
const bucket = storage.bucket(functions.config().firebase.storageBucket);
const filePath = 'images/*.png';
const file = bucket.file(filePath);
file.delete();
Or similar to be able to delete all files inside "images" with png extension.
I tried searching in Stackoverflow and in the samples repository without luck https://github.com/firebase/functions-samples
Any help would be much appreciated. Thanks!
No. In order to delete a file from Cloud Storage, you need to be able to construct a full path to that file. There are no wildcards or regular expressions.
It's common to store the paths to files in a database in order to easily discover the names of files to delete by using some query.
If you want to do this in Cloud Functions, you'll be using the Firebase Admin SDK. And the Cloud Storage functionality in there (admin.storage()
) is a thin wrapper around the Cloud Storage SDK for Node.js. So if you search for cloud storage node.js path regular expression
you'll get some relevant results.
bucket.getFiles({ prefix: 'path/to/file' }...
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With