3 回答
TA贡献1839条经验 获得超15个赞
此代码从媒体库中删除条目并从uploads目录中删除文件:
const file = await strapi.plugins['upload'].services.upload.fetch({ id });
await strapi.plugins['upload'].services.upload.remove(file);
TA贡献1783条经验 获得超4个赞
假设您的内容类型是文章,请尝试以下操作:
在/api/articles/controllers/articles.js
'use strict';
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
module.exports = {
async delete(ctx) {
const { id } = ctx.params;
const entity = await strapi.services.articles.delete({ id });
//with strapi multiple media
if(entity){
if (entity.gallery.length > 0) {
entity.gallery.forEach(image => {
strapi.plugins.upload.services.upload.remove(image);
});
}
}
//or with strapi single media
if(entity){
strapi.plugins.upload.services.upload.remove(entity.image);
}
return sanitizeEntity(entity, { model: strapi.models.articles });
}
}
TA贡献1824条经验 获得超8个赞
尝试调用 Strapi org. 控制器中的功能:
delete: async ctx => {
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].delete(ctx.params, ctx.request.query);
},
deleteAll: async ctx => {
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].deleteMany(ctx.params, ctx.request.query);
}
添加回答
举报