Custom middleware to limit images upload depending on their width and height via MediaLibrary

In our Strapi we need to limit the images uploads depending on their size and/or their width and height. We have been able to implement the size restriction by changing the formidable setting in config/middleware.js, but we are having troubles implementing the other restriction.

We have followed the middlewares config from the docs and created these files:

// config/middlewares.js

module.exports = ["plugin::upload.limitImageSize"];
// middlewares/index.js

const limitImageSize = require("./limitImageSize");

module.exports = {
  limitImageSize,
};
// middlewares/limitImageSize.js

module.exports = () => {
  return async (ctx, next) => {
    const start = Date.now();

    console.log("I'm in limitImageSize middleware: ", { ctx });

    await next();

    const delta = Math.ceil(Date.now() - start);
    ctx.set("X-Response-Time", delta + "ms");
  };
};

As expected, in limitImageSize.js we would like to implement something to limit the upload, but we are not able to even show the logs when the upload is happening.

Are we following the correct docs? What would be the way to create these files? And regarding the width and height limit, where should we start?

Hello, I tried the solution,But I am getting error

Error: Middleware plugin::upload.limitImageSize not found.