How to delete file from upload folder in strapi?

strapi file upload example
strapi-upload files are empty
strapi media library
strapi aws
strapi post
strapi plugin upload npm
strapi github
strapi documentation

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?

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);

Upload, Describe the bug Tried a DELETE request on {ipaddress}/uploads/{file_id}, but get a 404 Not Found. I am able to download files, so I know the  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Try to invoke the strapi org. functions in your controller:

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);
}

How to delete uploaded file through API · Issue #4103 · strapi/strapi , Informations Node.js version: v9.10.1 npm version: 5.6.0 Strapi I have two fields which both are upload-file fields, and I am using aws s3 Delete: { Objects: [{ Key: `${file.path}/${file.hash}${file.ext}` // add ${file.path}/ }] }. Customizing the admin is as simple as creating a file in the ./admin folder of your app. You need to make sure the file you want to customize is at the same location in your ./admin folder as it is in the strapi-admin package. For a reference you can look at the source code. # Example

Try the following, assuming your content type was article:

in /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 });
  }
}

How to specify upload-file field's directory? · Issue #1525 · strapi , Currently all files uploaded via strapi just go into the root of the Cloudinary files have been uploaded from which app, and thus no way to e.g. delete all of the  Handle File Upload with Express + Multer. File upload is a common feature that almost every website needs. We will go through step by step on how to handle single and multiple file(s) upload with Express, save it to database (LokiJs), and retrieve the saved file for viewing.

File Upload Strapi and React, Affected versions of the package are vulnerable to Directory Traversal. An attacker may POST or PUT a request to the /upload-files endpoint and make the request handler think a strapi-admin@3.0.0-alpha.26.2 › remove-markdown@​0.2.2  Select ON, for Enable File Upload; Click the Save button. You may now test the image upload, and you will find your images being uploaded to Amazon AWS S3. # Set up a webhook. Providing that your project is set-up on GitHub, you will need to configure your Strapi Project Repository with a webhook.

Add support for folders in Cloudinary - strapi, Technically, Strapi can use the local file system to store images. By default, Strapi uses a cache folder to store images uploaded to the server. This way, even if we delete the cache, the images will automatically be retrieved from the cloud. To enable this feature just change/add the "tracing": true option in the GraphQL settings file. You can read more about the tracing feature from Apollo here . You can edit these configurations by creating following file.

strapi 3.0.0-alpha.5, yarn add strapi-provider-upload-aws-s3-sharp-resize. Now that the provider is installed, create a settings.json file in the following directory. Add setup script and build on dev if not build folder ('strapi-provider-upload-')); for View file Edit file Delete file

Comments
  • Doesn't work for me. Exception is thrown: (node:16792) UnhandledPromiseRejectionWarning: Error: You can't call the query method without passing the model's name as a first argument.