'Convert files form input to arr and remove file
I decided to create one more validation, this time in user side (java-script).
I would like to do it in simple way. I decided to convert inputs files to the array, and then remove file.
my code
let uploadField = document.getElementById("file"); //mój input
uploadField.addEventListener('change', checkFileSize)
function checkFileSize() {
let amount_files = uploadField.files.length;
let files_array = Array.from(uploadField.files);
let maxsize = 3*1024*1024;
console.log(Array.isArray(files_array));
for(let i = 0; i < amount_files; i++) {
if(files_array[i] > maxsize) {
files_array.splice(i, 1);
}
}
console.log(files_array);
}
I think that on this line
if(files_array[i] > maxsize
I should put file size after "if" , but I don't know how to get it (i saw this property on console)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
