I can't find any options in the documentation for uploads on how to add a validation error for an image's dimensions. Has anyone implemented this before? Any info in any demos, or hopefully some docs that I've missed?
Thanks!
I believe you should use the hooks.beforeValidate to do this.
Edit: I have now tested it 😄
hooks: {
beforeValidate: [
(req): void => {
const image = req.data;
// Make sure uploaded image is big enough
if (image && image.width < 640) {
throw new Error('Image must be at least 640px wide');
}
},
],
},
Thanks heaps! Works smoothly and perfectly. I love a simple solution.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.