I want to upload a file like this:
Is there any way to find out in javascript if the se
Firstly add accept="image/*" on your input, to accept only image files
Second, you can create image object to see if it is true image
function validateAndUpload(input){
var URL = window.URL || window.webkitURL;
var file = input.files[0];
if (file) {
var image = new Image();
image.onload = function() {
if (this.width) {
console.log('Image has width, I think it is real image');
//TODO: upload to backend
}
};
image.src = URL.createObjectURL(file);
}
};