Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Multiple file size upload

default discord avatar
.bakrylast year
8

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
    last year

    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
    .bakrylast year

    can you elaborate more ?

  • discord user avatar
    jmikrut
    last year

    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
    .bakrylast year

    like this ?

    image.png
  • discord user avatar
    jmikrut
    last year

    exactly



    give that a shot

  • default discord avatar
    .bakrylast year

    yesss its working ty ty

  • discord user avatar
    jmikrut
    last year

    beautiful

  • default discord avatar
    _timboozle12 months ago

    hi! i was looking for this exact solution, however, i have no idea how to implement this. how and where would i need to provide this custom filesize field?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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