Can't set fileSize limit to Upload collection

default discord avatar
last year
1 1

I'm a bit confused about the docs. I understand how to set a global limit but I want different limits in different upload collections: ie I have an images collection and a videos collection. In my videos collection I tried adding both filesize and fileSize (different case in the docs) in upload but it throws errors. Then there is an example in the global config in which it's inside a limit object, it also throws errors.


access: {},
upload: {
  mimeTypes: ['video/mp4'],
  fileSize: 5000000, // 5MB, written in bytes

Throws Collection "videos" > "upload.fileSize" is not allowed


access: {},
upload: {
  mimeTypes: ['video/mp4'],
  limits: {
    fileSize: 5000000, // 5MB, written in bytes

Also throws Collection "videos" > "upload.limits" is not allowed

What would the correct way to declare this be? Thanks in advance, 💖 payload

  • discord user avatar
    Payload Team
    last year

    Hey @gonzam88 — I see what you're looking to do. And I think this is a totally reasonable request.

    As you've noticed, you can only specify global upload filesize limitations, but you can extend the built-in filesize field with a filesize field of your own, complete with a custom validation function that will enforce max upload sizes for you.

    Here's the built-in filesize field:

    const filesize = {
        name: 'filesize',
        label: 'File Size',
        type: 'number',
        admin: {
          readOnly: true,
          disabled: true,

    Just add that to your collection's base level with a custom validation function and then you're off to the races!

    1 reply
  • default discord avatar
    8 months ago

    I don't understand how to implement this. Can you give a bit more informations on where to add the filesize const in the collection and where to use it?

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.