Attachment Storage Issue in NocoBase

Hi,

I’m currently using the latest version of NocoBase (v1.8.7 running in Docker) and have encountered an issue with attachment storage.

When I delete a record or remove a file from the attachment field (via form edit), the file itself is not deleted from the storage. I’ve tested this with both the default local storage and an additional storage configuration, and the issue persists in both cases.

Could you please advise how to resolve this? Is there a setting or cleanup process I might have missed?

Thanks in advance for your support.
Regards
Nat

The attachment field does not currently support this scenario directly. However, you can achieve the desired behavior (automatically deleting files) by configuring the following:

  1. Create an association between your business table and the file table. Use either a One-to-one (has one) or One-to-many relationship. Set the ON DELETE rule of the relationship field to CASCADE.
  2. In the file storage settings associated with the file table, uncheck the option “Keep file in storage when destroying record”.

image

Thank you, ShleyZ — it works! The file is deleted correctly when I delete the main record (in a one-to-many relationship with the File collection table).

However, I’ve noticed that if I delete the file attachment directly from the Edit Form, the file is removed from the UI, but it still remains in the file storage.

Is this the expected behaviour?
Or is there a workaround or setting I can use to ensure the file is also removed from storage when deleted from the form?

image

Thanks again!
Nat

Delete file when remove item in a field is not supported for now. You can only delete them in file table if just removed.

A workaround may be to use workflow, when update your record, check file collection or association collection (many to many) to file collection, if any reference existing, and delete non-existed ones.

Thank you for your help. I have one more question.
Is it possible to add an attachment (photo, file) to an external data source (MySQL, MariaDB) by storing them in Nacobase file storage?

Regards
Nat

For external (database) data source, only “Attachment (URL)” field is supported for now.