HossamAli's avatar

Validating Iamges

I'm using Vue to view the selected image as soon as the user selects it, but i wanna know if there is a way to validate the image like check the dimensions and size and extension before uploading them or before the request is sent to the store method to store the image

0 likes
1 reply
Cronix's avatar
Cronix
Best Answer
Level 67

You can get a few of those things using javascript.

https://developer.mozilla.org/en-US/docs/Web/API/File

https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications

You wouldn't be able to get image dimensions as easily since the existing methods only work on all files (nothing specific to image upload). There is a trick, but it involves taking the file and putting it in an img tag (hidden with css) and getting the image dimensions that way, but you can't get it directly off the file itself like you can with the filesize, name and mimetype. There are js upload libraries like dropzone that can help with some of this as well.

1 like

Please or to participate in this conversation.