Chron's avatar

Dropzonejs: Is there a way to validate image dimensions?

I want to check the image dimensions before accepting the file. The problem is this, for eg, the maxFiles is set to 2, if I dragged like 5 files, it accepts all of them. That only happens when I added the last condition

I already have a validation in laravel but I also want another validation on frontend for added "security". Should I give up on this and just stick to the laravel validation?

1 like
3 replies
vincent15000's avatar

I think that you can validate the image dimensions server side only.

Chron's avatar

You can actually validate image dimensions with this one.

const image = new Image();
image.src = URL.createObjectURL(file);
image.onload = () => {
	URL.revokeObjectURL(file);
		if(image.width < 1200 || image.height < 800) {
			done('Dimension error');
		}
}
1 like

Please or to participate in this conversation.