How to delete a file through the Upload plugin from a controller

Figured out my problem so I’m sharing the solution here in case anyone else encounters this – the issue was in how I called the remove method. When you just pass it the id of the file, it will only delete the file entry in the database. Instead, pass the entire file object. Below is the revised code:

// Get file to verify it exists
const file = await strapi.documents('plugin::upload.file').findOne({
  documentId: certificate.attachment.documentId,
});

if (!file) {
  return ctx.notFound('File not found.');
}

// Delete the file from the database and file system
let result = await strapi.plugins.upload.services.upload.remove(file);