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 ?
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
can you elaborate more ?
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 👍
like this ?
exactly
give that a shot
yesss its working ty ty
beautiful
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
Discord
online
Get help straight from the Payload team with an Enterprise License.