I want to delete multiple objects from my google cloud storage, which means delete folders and files in combination. There is an example in the official documentation:
bucket.deleteFiles({ prefix: 'image-' }, callback);
This will delete all files in the images directory.
But what if I want to delete 10 000 files in this directory?
My demo code is this:
const _deleteItems = async (gcsClient, bucketName, allItems) => {
try {
for (let item of allItems) {
await gcsClient.bucket(bucketName).deleteFiles({ prefix: getFilePath(item) }, function(err) {});
}
} catch (err) {
throw new Error('Could not delete item');
}
};
Is there a better way to do this? What if someone else in the meantime upload new file in the folder that i am going to delete? That file also will be deleted in this case.