I want to write a cron job that removes any media file that does not attach to any entity in collection types or single types because the business requires to upload of many media files and a lot of them does not attach to any entity and I do not need them so I need a way to get all media files that not attached to any entity and remove it
Here is an approach that I would explore more for this kind of functionality.
- Get a list of media file in the uploads using GET /api/upload/files > Upload | Strapi Documentation
- Get all media attached on all entities in collection-types & single types.
- Filter out the results of step 1 that exist in step 2. You are left with an array that has media that are not attached.
- Using DELETE /api/upload/files/:id to delete the resulted array from step 3 recursively.
Hope this is helpful to get you started.