5

Is there any way to validate or limit what file-type/ extensions could be uploaded before it actually gets uploaded?

I've tried using a couple of custom-hooks but they all just went through.

Hooks tried:

  • files.create.before
  • items.create.before
module.exports = function registerHook({ exceptions }) {
  const { InvalidPayloadException } = exceptions;
  return {
    "files.create.before": async function (input) {
      console.log(input);
      throw new InvalidPayloadException("title");
    },
  };
};
  • Are you sure that the hook gets recognized by Directus? It should write in the console when loading an extension. Also, the app should be restarted as the extensions are loaded on startup from what I remember. – Daniel Stoyanoff Aug 31 '21 at 15:52

1 Answers1

2

If you scroll down past either Filter, or Action Events, you will see a small block listing all system collection names where files cannot be intercepted during create/update.

Maybe they're trying to keep it as a file manager which can store every types, then bind it through pivot table.

You could try creating a custom user interface where you limited the choice of uploading file extensions yourself (Not sure if it works).

enter image description here