Last active
October 7, 2021 12:15
-
-
Save Minobi/d1636982a6a545ffe09070f15becca77 to your computer and use it in GitHub Desktop.
Add and remove file from non-modifying FileList in input type "file"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addFile(fileInput, event) { | |
const dt = new DataTransfer(); | |
Array.from(fileInput.files).forEach(file => { | |
dt.items.add(file); | |
}); | |
Array.from(event.dataTransfer.files).forEach(file => { | |
dt.items.add(file); | |
}); | |
fileInput.files = dt.files; | |
} | |
function removeFile(fileInput, fileName) { | |
const dt = new DataTransfer(); | |
Array.from(fileInput.files).forEach(file => { | |
if (file.name != fileName) { | |
dt.items.add(file); | |
} | |
}); | |
fileInput.files = dt.files; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment