---
title: "Delete files when their owner is deleted · Agent Wranglers"
url: https://agentwranglers.se/playbook/api-design/files-and-uploads/delete-files-with-owner
updated: 2026-10-20
licence: "All rights reserved"
---

# Delete files when their owner is deleted

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Files and uploads](https://agentwranglers.se/playbook/api-design/files-and-uploads)
- Rule: Record every stored object in a files table with its owner, and delete the objects in the same job that deletes the owner.
- How: Make the delete job remove objects first, then rows, so a crash leaves rows to retry rather than unknown objects. On versioned buckets delete every version, or the file lives on. Include derived files, such as thumbnails and rebuilt images. Run a weekly sweep that lists the bucket and compares it with the table. Delete objects with no row that are older than 7 days. The request side, time limits and backups are in [let people see and delete their data](https://agentwranglers.se/playbook/website/privacy/data-requests).
- Check: Create a test owner with an upload, a thumbnail and two versions of a file. Delete the owner. A listing of the owner's prefix, including old versions, is empty. The weekly sweep reports zero objects without a row.

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers api design playbook: https://agentwranglers.se/playbook/api-design/files-and-uploads/delete-files-with-owner`.

- Previous: [Store the same file once per owner](https://agentwranglers.se/playbook/api-design/files-and-uploads/dedupe-by-hash)
- Next: [Neutralise formulas in spreadsheet exports](https://agentwranglers.se/playbook/api-design/files-and-uploads/spreadsheet-exports)
- [Files and uploads](https://agentwranglers.se/playbook/api-design/files-and-uploads)
