Delete Files from Image Fields and Record Attachments
One of the best methods to free up space in your Ninox solution is to periodically delete files stored in image fields or as record attachments.
Removing Files Stored in Image Fields
This can be done with a script which loops through a the image fields in a selected table, and removes the files before setting the image field to null. Please note: You must remove both the underlying file and set the image field to null for this to take effect. Here is an example:
for r in select Tabelle1 do
removeFile(r.Image);
removeFile(r.'Image 2');
r.(Image := null);
r.('Image 2' := null)
end
How to Implement it in your Database
Upload the example database to a workspace
Open the database and add a file to an image field for testing purposes
Press the 'Delete Image Field Content' button, and the file you added will be removed
Enter edit mode and click on the 'Delete Image Field Content' button
Copy the script
In your database, go to the table in you want to remove the files from
Create a button element and paste the script into the 'On click' formula. You will need to replace the table name (i.e. Tabelle1) in the select statement with your table name, and the image field names (i.e. Image and Image 2 in this case) with your image field's names
Press the button, and it will remove all files and in that table and set the fields they were stored in to null
You could also set date parameters wherein records are checked, and if their 'Created on' field is before a certain date, it removes all files from the image fields and sets them to null. This could also be applied to other date fields. Here's an example:
let cutOffDate := date(2025, 8, 31);
for r in select Tabelle1 where 'Created On' < cutOffDate do
removeFile(r.Image);
removeFile(r.'Image 2');
r.(Image := null);
r.('Image 2' := null)
end
Removing Files Stored in Attachments
The same principle applies, but it must be done slightly differently, as you only need to remove the file. Here is an example:
for r in select Tabelle1 do
for f in files(r) do
removeFile(r, last(split(text(f), "/")))
end
end
Upload the database provided below to a workspace
Open the database and add a file as an attachment for testing purposes
Press the 'Delete attachments' button, the attachment you added will be removed
Enter edit mode and click on the 'Delete attachments' button
Copy the script
Go to the table you want to remove the files from
Create a button element and paste the script into the 'On click' formula. You will need to replace the table name in the select statement with your table name
Press the button, and it will remove all file attachments in that table
You could also set date parameters wherein records are checked, and if their 'Created on' field is before a certain date, it removes all files from the record's file attachments. This could also be applied to other date fields. Here's an example:
let cutOffDate := date(2025, 8, 31);
for r in (select Tabelle1)[number('Created on') < number(cutOffDate)] do
for f in files(r) do
removeFile(r, last(split(text(f), "/")))
end
end;
IMPORTANT: In both examples, you must delete the automated backups after carrying out these changes in order for them to take effect. Please also note that the usage overview is only automatically refreshed once per day, so you may not see the reduction in the database's size until the following day.
Reply
Content aside
-
2
Likes
- 16 hrs agoLast active
- 32Views
-
1
Following