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, 💖 payload
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?
you can add this thing into payload config ts file
upload: {
limits: {
fileSize: Number(process.env.MAX_FILE_SIZE) || 10 * 1024 * 1024,
},
},
you can add this thing into payload config ts file
This only apply the limit globally. I think what @alexisbrouillette was asking was a way to set it on collection level.
@jmikrut if this is something that is great to have, I can prepare a PR. Basically what I have in mind:
upload fieldpackages/ui/src/elements/Upload/index.tsx#Upload_v4#handleFileChange and do toast.error when selected file is bigger than the size limitWhat do you think?
Any updates on this? Running into an issue where if a file is upload that is too big/very big- it just throws a timeout error.
I see the upload: { limits: { ... } } in the docs. Is that not available on the collection level? I saw the limits and thought, perfect- I'll apply this to each collection where we're doing this (each collection has a different upload size limit). However, I get the following error:
Object literal may only specify known properties, and 'limits' does not exist in type 'UploadConfig'.ts(2353) types.d.ts(558, 5): The expected type comes from property 'upload' which is declared here on type 'CollectionConfig'
Star
Discord
online
Get dedicated engineering support directly from the Payload team.