How to delete Firebase Storage files saved with FlutterFlow via Cloud Functions?

Database & APIs

Hi everyone! I've got an app where different users can upload photos and work with them together. In case the Administrator want's to delete this workspace - photos must be deleted as well. But the problem is that not all of them might be uploaded by Administrator himself. So just calling FF standard action to delete this files is not a solution. It must be done via Firestore Cloud Function, but the problem is, the path to uploaded files via FF is stored as an URL. For example, https://firebasestorage.googleapis.com/v0/b/my-app-s2bb3m.appspot.com/o/users%2F3cCPmzT4UDbMRbnl%2Fuploads%2F1732030640.jpg?alt=media&token=ab9e4586-06a6-466c-8323-ff9d3697bcfa

When I pass this URL to the

bucket.file(path).delete()

function it gives an error. Seems I must pass some relative path to the file like /users/3cCPmzT4UDbMRbnl/uploads/1732030640.jpg

Maybe there is a beautiful way to do that and not parse the initial URL?

What have you tried so far?
exports.onTransactionDelete = functions.firestore
.document('wallets/{walletId}/transactions/{transactionId}')
.onDelete((snap, context) => {
  var data = snap.data();
	return new Promise((resolve, reject) => {
    try {
      if(data.photos.length > 0) {
        const bucket = admin.storage().bucket();
        data.photos.forEach(function(p){
          bucket.file(p.path).delete().then(function () {}).catch(function (e) {
            console.log(e);
          });
          console.log('File deleted: ' + p.path);
        });
        resolve('Delete finished');
      } else {
        resolve('No photos');
      }
    } catch(e) {
      reject(e);
    }
  });
});
Did you check FlutterFlow's Documentation for this topic?
Yes
1
1 reply