Remove any media file that does not attached to any entity in collection types or single types

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

Hey @mhmodTayel,

Here is an approach that I would explore more for this kind of functionality.

  1. Get a list of media file in the uploads using GET /api/upload/files > Upload | Strapi Documentation
  2. Get all media attached on all entities in collection-types & single types.
  3. 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.
  4. Using DELETE /api/upload/files/:id to delete the resulted array from step 3 recursively.

Hope this is helpful to get you started.

Cheers!