Multiple file size upload

default discord avatar
Bakry
last month
14

I have 3 different type of uploads and i want to set a size limit for each one


Images : 1MB


Videos: 500mb


Audio : 25mb


i found a global option in the documentation any idea how can i do this for each collection ?

  • discord user avatar
    jmikrut
    Payload Team
    last month

    hmmmm this is a very good question



    right now we add the file-upload middleware once, on the

    /api

    router - - meaning it gets passed options only once



    i think this could be done by passing a custom

    filesize

    field



    where you can write a validation on that field

  • default discord avatar
    Bakry
    last month

    can you elaborate more ?

  • discord user avatar
    jmikrut
    Payload Team
    last month

    ok so for every built-in field that Payload exposes, if you

    pass the config your OWN, with the same name

    , Payload will "match" your provided field and merge in its defaults, with your settings as preference



    here are the base upload collection fields that Payload injects:



    https://github.com/payloadcms/payload/blob/master/src/uploads/getBaseFields.ts


    if you swap in a field with name

    filesize

    , you could merge in a custom

    validate

    function that enforces your restrictions đź‘Ť

  • default discord avatar
    Bakry
    last month

    like this ?

    image.png
  • discord user avatar
    jmikrut
    Payload Team
    last month

    exactly



    give that a shot

  • default discord avatar
    Bakry
    last month

    yesss its working ty ty

  • discord user avatar
    jmikrut
    Payload Team
    last month

    beautiful

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

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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