Delete image from database

I’m surprised this has stumped me, should be easy! How do I delete a Users profile image from the database? I have tried the following;


delete image2

Is the image a datatype?

I don’t know! See database below …

No, you don’t have an Image datatype, so you can’t delete it from your database, as it’s not in your database.

The image is just a file, stored in your file storage, and set as a field on your user datatype.

In fact, you asked this exact same question the other day (maybe you forgot) which I already answered - the answer still applies:

Delete a thing from database - Need help / Database - Bubble Forum

But to recap the answer briefly:

‘Delete a Thing’ is for deleting ‘Things’ (DB entries of a specific datatype) from your database. You don’t have an Image datatype, so you can’t use this action. You could create an Image datatype (and it might not be a bad idea, but it depends on what data you need to store, and other use-case specifics), in which case you would then use this action to delete an Image ‘thing’, which would also automatically remove it from any field it was in on a User DB entry (you’d still need to delete the file, if you want to remove it from your file storage).

To clear a field just make changes to the thing (the current User) and leave the field (Image) value blank.

To delete a file use the ‘Delete an Uploaded File’ action (to delete the current User’s Image).

If you’re doing everything correctly and still can’t get things to work as you intend them too, then check in the debugger and/or your server logs to see in more detail where and when any issue could be occurring. Privacy rules are often a cause of issues, so make sure you’ve set the correctly as well.

5 Likes

Hey Adam,

Yes, you did explain this … I’m still in the ‘information overload’ stage of learning but it is seeping in! This answer of yours seems to have clicked with me. I get it now, a Data Type is like the main Folder (Users, Events) and the DB entries are the ‘files’ in that folder (wish they were referred to like this as more intuitive).

So, I can delete the main ‘folders’, but the ‘files’ are stored in your file storage. Your solution to clear a field works perfectly.

I am not sure on best practice for the future. Will it become very expensive and data heavy if I have loads of users who can never delete their images? I suppose most people don’t bother to delete their images if they stop using a service so probably not a big deal.

Anyhoo, thanks for the help and patience.

It’s not really similar to folders and files on a computer (not at all actually). If you were making an analogy along those lines then it would be more similar to ‘file-types’ and ‘files’.

But it’s not helpful to think of database entries as files (they’re certainly not that), and datatypes certainty aren’t folders.

Rather a datatype is a particular ‘type’ of data that you want to store in your database. ‘Things’ (database entries) are just that - specific entries in the database of that particular type of data.

For example, if you wanted to store information about cars, you could have a datatype of ‘Car’ and set up all the fields you need for the data you want to store (such as manufacturer, model, year, colour, etc.).

Then, each entry would be for a specific car, along with all that car’s individual data.

Then you can also refer to that datatype in fields of other datatypes if you need to.

So, I can delete the main ‘folders’, but the ‘files’ are stored in your file storage. Your solution to clear a field works perfectly.

No, if you’re using that analogy then that’s incorrect - you can’t create or delete datatypes (folders in your analogy) from within the app itself through workflows (only from within the editor).

But again, it’s not helpful to think of datatypes as folders, and files are something else entirely.

You’re right that ‘files’ are stored in your file storage, which is separate from the database.

I am not sure on best practice for the future. Will it become very expensive and data heavy if I have loads of users who can never delete their images? I suppose most people don’t bother to delete their images if they stop using a service so probably not a big deal.

It won’t have any effect on ‘data’ but if you have a lot of images in your file storage that aren’t being used then, as Bubble only gives you a relatively small amount of file storage, it will eventually be taking up storage space unnecessarily.

So it’s definitely a good idea to delete unused files (especially when using Bubbles file storage).

The Bubble manual explains very well the concept of datatypes and how to structure your data, so it’s well worth having a read through in order to understand it better:

Creating a Data Structure - Bubble Docs

2 Likes