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.
Videos.js
...
access: {},
upload: {
mimeTypes: ['video/mp4'],
fileSize: 5000000, // 5MB, written in bytes
}
Throws Collection "videos" > "upload.fileSize" is not allowed
Videos.js
...
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,
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!
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?