如何从trapi的上传文件夹中删除文件? [英] How to delete file from upload folder in strapi?
本文介绍了如何从trapi的上传文件夹中删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含媒体类型字段的条目.
I have an entry with field of type media.
当我尝试删除某些条目时,我正在使用代码:
When I'm trying to delete some entry, I'm using code:
strapi.query('entry').delete({ id: entry.id });
strapi.query('file', 'upload').delete({ id: entry.image.id });
该条目已成功删除,以及文件上传"中的记录.但文件仍保留在上传文件夹中.我怎样才能删除它?
The entry is deleted successfully, as well as record from "Files Upload". But file still stays in upload folder. How can I delete it?
推荐答案
此代码从媒体库中删除条目并从 uploads
目录中删除文件:
This code removes entry from Media Library and deletes files from uploads
directory:
const file = await strapi.plugins['upload'].services.upload.fetch({ id });
await strapi.plugins['upload'].services.upload.remove(file);
这篇关于如何从trapi的上传文件夹中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文