Directus v9 file-type validations before upload

Viewed 265

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");
    },
  };
};
1 Answers

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

Related