Pagination not working for "api/upload/files" endpoint

Just an extra for anyone who can edit their backend, you can make the files endpoint more like other api endpoints:

Inside: src/index.js

// make the register block look like this:
  register({ strapi }) {
    strapi.plugin("upload").controllers["content-api"].find = async function (ctx) {
      const { start, limit } = ctx.query
      const firstPageAdd = start > limit ? 0 : 1
      const files = await strapi.plugin("upload").services.upload.findMany(ctx.query);
      const total = await strapi.db.query('plugin::upload.file').count(ctx.query)
      const data = await sanitizeOutput(files, ctx)
      ctx.body = {
        data, pagination: { pageCount: files.length, pageSize: limit, total, page: Math.ceil(((start - firstPageAdd) / limit) + 1) }
      };
    }
  },

remember to import sanitizeOutput

1 Like