
Check if a media is used in a content before deletion
released October 14, 2026
npm install @openstudio/strapi-media-deletion-middlewareCheck if a media is used in any content before deleting it.
Works with strapi 4 and 5
npm i @openstudio/strapi-media-deletion-middleware
# Or
yarn add @openstudio/strapi-media-deletion-middlewareAdd in config/middleware.ts
module.exports = ({ env }) => [
// ...
{
resolve: '@openstudio/strapi-media-deletion-middleware',
},
// ...
];To modify some default values add a config object with the config key you want to edit.
module.exports = ({ env }) => [
// ...
{
resolve: '@openstudio/strapi-media-deletion-middleware',
config: {
strapiMajor: 4,
blackList: [{ relatedType: 'api::article.article', field: 'cover' }],
whiteList: [
{ relatedType: 'api::article.article', field: 'optionalField' },
],
},
},
// ...
];| key | description | default |
|---|---|---|
| strapiMajor | Strapi Major version in this project possible values : 4 or 5 | 5 |
| blackList | Specify a list of elements whose medias CAN'T be deleted, an empty list means everything is in the black list | [] |
| whiteList | Specify a list of elements whose medias CAN be deleted, for instance if a media is in an optional field you might allow to delete it | [] |
Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.
Submit
