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

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!

1 Like