Delete app images or files in an app record from Google Drive itself when you delete the record from the app

There are many posts in the community about wanting to delete the image files also from the Google drive when a row in a table is deleted.

One can do so using the feature of “Folder as a table” introduced around one year ago. We can use this feature to delete the image and other document files from the Google drive itself when the row in the app is deleted.

Steps

  1. Add the folders names from G drive where images and files from the app are stored as tables in the app.
    Document Processing - Folder as a Table

  2. Make these newly added (folders as ) tables with delete permissions. In the image below the table “ImagesnFile_Files_” is the folder in G Drive where files are stored.

  3. Create reference actions from the normal table where these images and files are used to delete the images and files when the row from the app is deleted. The referenced rows of the image / file folder tables can be obtained from the below expression

SELECT(ImagesnFiles_Files_[_ID],CONTAINS([Path],[ID]))

The important point here is that the Image and file folders based tables have a [Path] field that always contains key of the table from where the image was saved. The path field of the Image folder table is shown below

The image below shows how the image path is saved in the table where the app saves the image in image type column. As we know, an image or file always gets saved with the key of the table appearing in its saved path.

So essentially we can use the key of the table where the row is saved to reference and delete the associated image from the image folder table with reference action. The point to note is that referenced delete action on the folder table deletes the image from the G drive itself

You can have group actions to first delete the associated images or files from image and file folders in the G drive followed by the delete action on the table itself where the row is deleted.

The deleted inages from G drive go to its trash folder from where those are automatically deleted after 30 days.

Point to note One need not depend on normal table record to be deleted to delete the associated images or files in the record from the G drive. One can simply delete the images and files from the folder tables itself. One however needs to be careful that these images or files are not set as “required” and “labels” or main images in deck view etc. to break the app or lower the app usage experience.

Associated posts and requests

13 12 3,718
12 REPLIES 12

We have apps with similar settings, but challenge was how to deal with the case where the users goes to existing row and swap image to new one and save. The requirement was to delete the old image from drive. So what we did is to store the “previous” image path in other column physically on the same row using [_thisrow_before] operator and fire the delete action from table (generated from folder) to delete old one.

Just add another tips.

Hi @Suvrutt_Gurjar what a great post thank you!
Does the sync time increase when you add the “Folder as a table”?

Hi @Fabian ,

Thank you. You have a very good question. I had tested the concept on a test app with small number of records. I currently do not have an app handy with very large number of images in the images folder. Will share observation when I build test data accordingly.

Please do share your observation if you happen to test with large number of records.

Hi @Suvrutt_Gurjar We have a folder with 2 GB images. This takes more than 1 minute to sync. So we found this solution:

We use a bot that deletes the images every night.
In the folder's security filter we put in "FALSE" so that the sync time will not increase.
In the bot we enable "Bypass Security Filters?" so that the bot can read the folder.
In the bot we use this Filter Condition:

ISBLANK(
ANY(
SELECT(Images_Table[Image_Column],
ENDSWITH([Image_Column], INDEX(SPLIT([_THISROW].[Path], "/"), 5))
)
)
)

Thank you for sharing this method @Fabian_Weller . Your solutions/ approaches are always interesting. It sounds that you delete certain number of images on a daily basis.  Is it correct understanding?

Yes this expression checks for every image file if it's still in the images table. If not, the bot will delete it. This happens every night.

This Expression maybe a bit more efficient:

NOT(CONTAINS(Images_Table[Image_Column],[File])

This comes without a SELECT() expression and makes use of the [File] column we have in "Folder as a Table".


@Suvrutt_Gurjar wrote:

You can have group actions to first delete the associated images or files from image and file folders in the G drive followed by the delete action on the table itself where the row is deleted.


Can you confirm that this is working? A delete action will stop the sequence in a grouped action. So in this case, the file will be deleted in google drive, but then the delete action to delete the row will not fire.

Hi @Fabian_Weller ,


@Fabian_Weller wrote:
@Suvrutt_Gurjar wrote:

You can have group actions to first delete the associated images or files from image and file folders in the G drive followed by the delete action on the table itself where the row is deleted.


Can you confirm that this is working?


Thank you for reaching out. I checked the test app I had made.  The group action does delete the images and files in G drive as well as the row from the table.

The group action looks like below

Suvrutt_Gurjar_0-1659955019197.png

The third "Delete" action above is the delete action on the table where images and files are shown in the app.

The first two actions "DeleteAssociatedImages" and "DeleteAssociatedFiles" are reference actions that invoke from the table where the file and images are shown in the app. The reference actions in turn work on rows of the G drive folders tables  configured in the app. These G drive folders are where actual image and PDF files are stored in G drive,

I think the third delete action works because the first two delete actions are on different tables.

If you want I can share the test app with you. Please DM me the email ID where you would like me to share it.



 

 

Thank you so much @Suvrutt_Gurjar I was confused about delete + navigate, which is not working.

Have you seen also my other post? I sometimes easily overlook a post in this community.


@Suvrutt_Gurjar wrote:

SELECT(ImagesnFiles_Files_[_ID],CONTAINS([Path],[ID]))


I can't get this to work. Can anybody help me troubleshoot my implementation?

I have a table called `photo` and I've added the GDrive folder as a table called `photo_Images`. I created a bot that triggers on the "Photo record is deleted" event. It runs one step, configured like this:

Screenshot 2023-08-29 at 11.29.22 AM.png

Here is the entire referencing formula, including the schemas of the two tables involved. (Note: one of the tables is _photo_cache_Images, but it's the same schema as _photo_Images. I merely have two photo storage locations in this app.)

Screenshot 2023-08-29 at 11.30.24 AM.png

When I delete a photo in the app, the bot runs but doesn't delete the file. Automation monitor shows this data from the process step...

 

#
2
Name
Delete file from photo_Images folder
Created TimeStamp
8/29/2023 5:24:10 PM
Output data
{
  "id": "ed4b18fa",
  "asset_id": "bb23806f",
  "file_url": "_photo_cache_Images/9d6ee1a5.photo2.172352.jpg"
}

 

...which doesn't help me at all. Can anybody say what I've done wrong?

 

Hi @Stobber ,

If you are triggering the bot when the parent is deleted, then the further reference action will not work because it will loose the reference to the parent record in the expression because the parent record itself is first deleted.

SELECT(ImagesnFiles_Files_[_ID],CONTAINS([Path],[ID]))

I requested a simple action based execution and not automation. If you still want to go automation way,  please take a look at the below post.

Solved: delete children record from Parent Table - Google Cloud Community

If you go action way that I mentioned in the post, please go through the below

Please ensure you execute the reference action first and thereafter delete action on the parent record. I have clearly mentioned it as follows


@Suvrutt_Gurjar wrote:

You can have group actions to first delete the associated images or files from image and file folders in the G drive followed by the delete action on the table itself where the row is deleted.


So your group action can look like 

1. Reference action that deletes images from Images folder table

2. Delete action on the parent table ( "Photo" table in your case, assuming this table has other data in record apart from image)

This action needs to be set on the parent table. ( "Photo" table in your case, assuming this table has other data in record apart from image)

In my test app the sequence looks like below

Suvrutt_Gurjar_0-1693369336251.png

 

Here the third delete action is on the parent table. The first two are reference actions that delete images and files from the G drive.

Hope this helps.

 

Top Labels in this Space