Handling orphaned files in Bubble storage

I’m interested in how other people handle using Bubble’s native file storage solution. I know a lot of people will say ‘just don’t’ and use AWS but I still want to hear some practices that people are using to make it easier.

The problem is that it’s not straightforward to search the database for Files, and it’s easy for files to become orphaned such that they can only be deleted from the editor.

My current workflow is that whenever a file is uploaded to the site, a new File is created. File is a data type that contains the file, file’s name, the User/Thing that uploaded it, and any other app specific stuff.

That means that instead of using file (bubble file) fields, I use File fields (the File data type) when I want to reference file’s in the database. So, if I wanted to show a project RFP’s document it would be something like Project Request’s File’s file.

This also means I can create folder-like structures on the app by having a Folder data type and a list of Folders and Files on each folder, and people can rename displayed files within Bubble (although not the file itself).

Are there any other tricks I’m missing? This has just become my go to method to avoid the file manager overflowing - to delete a user’s files you just Do a search for Files of that User and recursively delete them. Hoping to learn something new :slight_smile:

1 Like

Hey George, I’ve seen you actively in the form and just want to say I respect the contributions you make!

I follow a similar method of having a “Media” data type and inside “Media” I have fields that help me add some context to the image or video file.

Generally for orphaned files, I use database triggers to delete them. I have a field named “Deleted” which is a yes or no. My trigger is looking for “Media before’s deleted = no and Media now’s deleted = yes”.

I do this for most objects that have the chance of being deleted because there are usually a set of action’s I need done after something is deleted.

1 Like

Oh this is neat - so you can just make changes to a list of things rather than schedule API workflow on a list / recursive workflow to delete files.

1 Like

Exactly! Or when someone deletes an image on their profile, my client side workflow is simply “make changes to media file → deleted = yes”