Removing Unwanted Files from the FileList
When working with a HTML5 drag-and-drop file upload application, you may encounter a situation where you need to remove certain files from the selected FileList. While it may seem straightforward, it's not possible to delete individual files directly from the list. This is because the FileList attribute is defined as readonly in the HTMLInputElement interface.
However, you have an alternative option. To remove all files from the FileList, you can explicitly set the value property of the input element to an empty string. Here's a code example:
document.getElementById('multifile').value = "";
As the empty value will remove all files from the input element, it's essential to note that this approach deletes the entire list. If you require more granular control, you will need to implement checks in your code that interacts with the FileList. While this may seem cumbersome, it allows you to retain specific files while discarding others.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3