Level 63
I think that you can validate the image dimensions server side only.
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
import fileTypeChecker from "file-type-checker";
accept: async function(file, done) {
const buffer = await file.slice(0, 64).arrayBuffer();
const detectedFile = fileTypeChecker.detectFile(buffer);
if(this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
done('Max files');
} else if(this.options.maxFilesize && file.size > this.options.maxFilesize * this.options.filesizeBase * this.options.filesizeBase) {
done('Too large');
} else if(!Dropzone.isValidFile(file, this.options.acceptedFiles) || detectedFile?.mimeType != file.type) {
done('Invalid');
}
//this one
else if(detectedFile?.mimeType.substr(0,5) === "image" &&
(minWidth || minHeight)) {
const image = new Image();
image.src = URL.createObjectURL(file);
image.onload = () => {
URL.revokeObjectURL(file);
if(image.width < minWidth || image.height < minHeight) {
done('Dimension error');
} else {
this.options.accept.call(this, file, done);
}
}
} else {
this.options.accept.call(this, file, done);
}
},
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?
Please or to participate in this conversation.